classroom.manager can be null on the server. So it may not come from server. I want to add it and create with my own constructor if it does not come from server. If it comes from server I want to create it with it’s own data.
var mappingOption = {
create: function (classroom) {
var res = ko.mapping.fromJS(clasroom.data);
if (res.manager == undefined)
res.manager = ko.observable(new Manager());
return res;
},
'manager': {
create: function (args) {
var res = ko.mapping.fromJS(args.data);
var res2 = new Manager();
$.extend(res2, res)
return res2;
}
}
Class room model
Manager model
Key part is the
data || new Manager()section