I am using Knockout.js as a MVVM library to bind my data to some pages. I\'m currently building a library to make REST calls to a web service. My RESTful web service returns
I would use the knockout mapping plugin.
var jsonData = {
id : 1,
details: {
name: "Johnny",
surname: "Boy"
}
}
var yourMapping = {
'details': {
create: function(options) {
return Details(options.data);
}
}
}
function Details(data) {
ko.mapping.fromJS(data, {}, this);
}
function YourObjectName() {
ko.mapping.fromJS(jsonData, yourMapping, this);
}
This will create your object hierarchy with all of the children as observables.