I want to save view model in the hidden field in JSON format. All work fine.
But when I try to get it - I get error:
Uncaught Error: Unable to
You are calling the ko.mapping.fromJSON with wrong arguments.
The correct usage in your case is the following:
var viewModelDeserialized =
ko.mapping.fromJSON(serializedJsonString, {} /* empty options */, viewModel);
Demo fiddle. (without the binding error)
The usage of the ko.mapping.fromJSON method is a little bit tricky:
you can call it with one argument: providing just the data e.g var viewModel = ko.mapping.fromJSON(data) in this case it will return the created viewModel
you can call with two arguments:
ko.mapping.fromJSON(data, koMappingCreatedViewModel)var viewModel = ko.mapping.fromJSON(data, options) you can call it with three arguments explicitly specifing the data, mapping and target: ko.mapping.fromJSON(data, options, target)