Problem
I have played around a lot with the knockoutJS mapping plugin.
My problem can be best shown in the following jsFiddles.
This one works. But this dont work.
I get the the error in the console
Uncaught Error: ko.mapping.updateFromJS, use ko.mapping.fromJS instead. Please note that the order of parameters is different!
Why i get this error and whats the difference in the fiddles ?
My Code
var viewModel = ko.mapping.fromJS({
"State" : 1,
"Text" : "Hello"
});
$("button").click(function()
{
var response = {
"State" : 2,
"Text" : "World"
}
ko.mapping.updateFromJS(viewModel, response);
});
ko.applyBindings(viewModel);
You are using different versions of the ko mapping plugin:
In your working fiddle:
http://wiredwestwebdesign.com/knockout.mapping.jsIn you not working fiddle:
https://raw.github.com/SteveSanderson/knockout.mapping/master/build/output/knockout.mapping-latest.jsAnd the method in question
ko.mapping.updateFromJSwas deprecated about a year ago in this changeset: First part of removing the updateFromJS* calls.And how to fix this error:
Just do what the exception says: use
ko.mapping.fromJSand watch for the parameter order:Demo fiddle.