This is a migrated thread and some comments may be shown as answers.

Binding not working even after re-wired

2 Answers 9 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Stacey
Top achievements
Rank 1
Stacey asked on 27 Nov 2013, 11:35 PM
I have a situation where I need to retrieve some data from my server, and then populate my view model with it. However when I do that, the bindings get overwritten. So I have a function to re-wire the functions and such for all of the various objects, and this seems to work fine; Except for this one situation where a sub-array of a top level property has an onCreate function.

The best I can see, when I start the page, the onCreate function has a property called "guid'. When I use the set function to apply the server side data to the array, that property is taken away, and I cannot seem to get it back. So the Click event fails with an error.

I have a jsBin sample here;

jsBin

2 Answers, 1 is accepted

Sort by
0
Stacey
Top achievements
Rank 1
answered on 29 Nov 2013, 05:30 PM
Been working on this for two days straight, still no success. Starting to think that it isn't even possible.
0
Daniel
Telerik team
answered on 02 Dec 2013, 08:33 AM
Hello Stacey,

The click handler should be assigned before the binding is being refreshed. In this case, before the Rails object is set in the fromJSON method. You should either assign the handler and then rebind the element:
change: function (e) {
    // get the selected row from the grid
    var selected = this.select();
    // get the data from the selected row
    var data = this.dataItem(selected);
    // update the model
 
    viewModel = new Model(data.toJSON());
    $.subscribe(viewModel);
    kendo.bind($("#binding-content"), viewModel);
}
or create a new ObservableObject for the Rails field and assign the handler before setting it to the viewModel.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Stacey
Top achievements
Rank 1
Answers by
Stacey
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or