I have a selectedCustomer(customer) observable where customer has 3 properties: Fname,LName,Age.
I data-bind those 3 properties to three text inputs and allow the user to edit them. How do I cancel the changes and revert those three properties back to their original state?
I was able to make a clone of it using:
var custCache = ko.observable(ko.mapping.toJS(customer));
I don't want to do manual mapping like below as this can get troublesome when your object has a lot of properites and arrays of other objects.
selectedCustomer().Fname = custCache().Fname;
selectedCustomer().Lname = custCache().Lname;
selectedCustomer().Age= custCache().Age;
So how do I put the values back to customer object when the user cancel the changes? How do I loop those properties and copy them over?
Thanks, Kevin