I need to clone some data from a master source in the ViewModel into a dialog. The reason being is that the user could cancel the dialog, and I don't want the master to reflect those cancelled changes.
I create a cloned copy of the master data into the dialog, and the data-bindings are set to pick up 'localEdited.*' properites. If the user clicks ok, I then try and persist the data back to the master if its edited, otherwise push the data if its new data.
editItem: function(data) {
// clone a temporary copy for the dialog
this.localEdited = ko.mapping.fromJS(ko.toJS(data));
$("#dlgAdd").dialog("open");
},
The above currently works, however if I click another item in the master, the dialog isn't showing the updated values. Its as if the ko.mapping.fromJS only works once and then never again. It always picks up the first values. How do I get around this problem? I feel like I need to re-bind the values, but the whole point of KO is to not have to do this.
How do I also persist the data back to the parent. I guess I might have the same problem as above.
BTW, I'm using KnockoutJS 1.2.1.