I have a javascript object (viewModel) that is binded to view . I’m getting new version of it (newViewModel) from server . (You can imagine stock market price application at this point)
I don’t want to bind newViewModel because I dont want to loose old viewModel’s reference.
So I need update all properties of my existing javascript object from server response !
This is maybe javascript question but my viewModel have so many observable properties and sub-properties. (knockout’s observable)
Ps: jQuery’s $.extend does not work.
UPDATED (It seems ok):
ko.mapping.fromJS(newViewModel,viewModel); seems working .. I could not recognize it, because “Vs.Net Intellisense” did not show overloads of it.
My object is very deeply structured. if I see any problems I will inform you.
UPDATED (Does not work):
viewModel.x[] length=2
newViewModel.x[] length=12
The code above replaces all x with new ones. (I lost viewModel.x[0],viewModel.x[1] references) !!
So my html is not synchronized with my objects. viewModel.x[0] in the basket on the right side but it
is not in the basket on the left side (screen)
There is no magic way for it.. Because I need to match old array elements with news. “Code” needs to know “keys” of array elements..
I visit all array elements if I could find newElement in my old array I update oldElement’s properties if I could not find I add newElement to oldArray.
Painful but I had to do.