I'm brand new to using Knockout.js and have just installed/instantiated a ViewModel binding using ko.mapping.js only to find that I get a partial binding.
Using the example code listed below we see that the binding works for the simple data but not the complex data in the JSON object. Here's a Fiddle
Complex JSON object:
var json = {
"a": "A",
"b": [{
"b1": "B1",
"b2": "B2",
"b3": [{ "one": "One", "two": "Two"}]
}],
"c": "C"
}
HTML Elements to bind to:
<div data-bind="text: a"></div>
<div data-bind="text: b.b1"></div>
<div data-bind="text: c"></div>
Javascript ViewModel/binding:
var vm = {};
vm = ko.mapping.fromJS(json);
ko.applyBindings(vm);
Have I missed something?
In Knockout.js, is it possible to bind a complex JSON object to a viewmodel using knockout.mapping.js?
If not, using this example ...how can we bind this complex JSON object using knockout.js?
The closest existing StackOverflow post I've been able to find is this one, Knockout mapping complex object
and I've tried for hours now utilizing multiple approaches and have been unsuccessful in being able to you the ko.mapping.js to do this binding.
And unfortunately the Knockoutjs.com documentation (http://knockoutjs.com/documentation/plugins-mapping.html) doesn't cover whether or not this is even possible with the plugin.