Adjust your mapping options to make it look like a creature, you give it a specific structure. He will then make updates for you.
Most likely, your DataFromServer does not actually contain the ScheduleList property. Therefore, when it is displayed, the corresponding property is never created. Mapper will only map existing properties to observables.
You need to specify in the create parameters that the view model adds empty arrays when no array is specified. That way your view model will have corresponding observable arrays.
By ensuring that the CourseList or ScheduleList is an array, the displayed model will display them as observableArray objects so that your code works as you would expect.
var DataFromServer = { 'CourseList': [1,2,3] //, 'ScheduleList': [] }; var dataMappingOptions = { 'create': function (options) { var data = options.data; data.CourseList = data.CourseList || []; data.ScheduleList = data.ScheduleList || []; return ko.mapping.fromJS(data); } }; viewModel.Data = ko.mapping.fromJS(DataFromServer, dataMappingOptions);
Jeff mercado
source share