I have a view model coming from the server as json like this
{
Project: {
Items: {
ItemA: {
Tags: [
...
]
},
ItemB: ...
}
}
}
I'm then binding this object with the knockout.mapping plugin, but I need ItemA to have, for instance, an additional Marked observable, such that I in the markup could do something like
<ul data-bind="foreach: Project.Items">
...
<input type="checkbox" data-bind="checked: Marked">
I tried using the create
option in the mapping process (as shown here ko.mapping create function, extend object), but I can't figure out how to nest the create
method to extend the objects in Project.Items.
I've been trying mappings like this
var mappings = {
'Items': {
create: function (options) {
return $.map(options.data, function(obj) {
return new Item(obj);
});
}
}
}