Take a look at this JSON object:
{
"BusinessModels":[
{
"Id":1,
"Name":"Business to Business",
"Businesses":[],
"ReportTypes":[
{...},
{...},
{
"Id":6,
"Name":"Risk",
"BusinessModelId":1,
"Reports":[
{
"Id": 4,
"Name": "Test",
"Value": ko.observable() // NEED TO ADD THIS PROPERTY USING MAPPING
},
{...}
]
}
],
}
]
}
I'm attempting to include the value using the code below, but it's not working as expected.
var mapping = {
'BusinessModels': {
create: function(options) {
return new function() {
var self = options.data;
self.SelectedBusiness = ko.observable();
self.Businesses.unshift({ Id: 0, Name: 'All Clients' });
ko.mapping.fromJS(self, {}, this);
};
}
},
'Reports': {
create: function (options) {
return new function () {
var self = options.data;
self.Value = ko.observable();
ko.mapping.fromJS(options.data, {}, this);
};
}
};
var model = ko.mapping.fromJSON(raw, mapping);
ko.applyBindings(model);
I need to assign a ko.observable
object named Value
to the child object "Reports". How can I achieve this using ko.mapping?