我从 knockoutjs 收到以下错误。它大部分时间都清楚地知道 AreaNames 是什么,因为 UI 显示 AreaNames 正在显示,但在某些时候,javascript 会因错误而冻结。
Uncaught Error: Unable to parse bindings.
Message: TypeError: Object #<Object> has no method 'AreaNames';
Bindings value: foreach: ActiveDay().AreaNames()
相关代码:
<ul data-bind="foreach: ActiveDay().AreaNames()">
<li data-bind="text: $data"></li>
</ul>
var scheduleModel = function (shiftCellToggle) {
var vm = this;
vm.ActiveDay = ko.observable({ AvailableShiftCategories: [] });
vm.CustomMapping = {
'Weeks': {
create: function (options) {
var week = new scheduleWeekModel(vm, shiftCellToggle);
ko.mapping.fromJS(options.data, week.CustomMapping, week);
return week;
}
}
};
}
var scheduleWeekModel = function (scheduleModel, shiftCellToggle) {
var vm = this;
vm.CustomMapping = {
'Days': {
create: function (options) {
var day = new scheduleDayModel(scheduleModel, shiftCellToggle);
ko.mapping.fromJS(options.data, day.CustomMapping, day);
return day;
}
}
};
var scheduleDayModel = function (scheduleModel, shiftCellToggle) {
var vm = this;
vm.CustomMapping = {
'AvailableShiftCategories': {
create: function (options) {
var availableShiftCategory = new availableShiftCategoryModel(scheduleModel, vm, shiftCellToggle);
ko.mapping.fromJS(options.data, availableShiftCategory.CustomMapping, availableShiftCategory);
return availableShiftCategory;
}
}
};
vm.AreaNames = ko.observableArray([]);
var viewModel = new scheduleModel(createShiftToggle());
ko.applyBindings(viewModel);