-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updateFromJS broken? #6
Comments
Hi abp, This is by design. Basically, the model you pass to updateFromJS represents the 'current state' of your model that comes from your server. The mapping plugin then takes this current state and updates your mapped viewModel to match this state, so that your GUI also shows the current state. In your example, therefore, it would remove the elements with keys '1' and '3' since they are not in your 'current state'. In a real-life scenario, maybe this is because some other user deleted items #1 and #3 since the last update occured. If you want to do regular merging, that would be something you'd have to do yourself, manually. I hope this explains why you are seeing this behavior. If not, feel free to reopen this ticket :) |
Sure, answers my question right to the point. Sorry for reporting a bug on this. :) |
No, that's okay! When writing your merge code, please note there's a useful "ko.utils.compareArrays" available that allows you to do diffs of two arrays. That can be a good starting point for you, I think. |
Thanks for the hint, but now i already have a dead simple remove/add based merging. Will see how it works out. :) |
Excellent! Good luck :) |
Hi,
i'm trying to use updateFromJS to merge data back into a fairly complex viewModel after the data is saved and probably changed on the server.
But it seems updateFromJS is replacing all the data instead of merging. I thought it would merge. So, am i doing something wrong or is it broken?
Here's a sample test case:
http://jsfiddle.net/rBRJZ/2/
The text was updated successfully, but these errors were encountered: