有人可以告诉我为什么这不起作用吗?
function Event() {
self.EventName = ko.observable();
self.EventTypeID = ko.observable();
self.EventTypeName = ko.observable();
self.DepartmentID = ko.observable();
self.DepartmentName = ko.observable();
self.EventDescription = ko.observable();
self.EventDate = ko.observable();
self.EventItems = ko.observableArray([]);
self.MembersAttended = ko.observableArray();
};
self.EventToAdd = new Event();
self.EventToAdd.EventName = 'test';
self.EventToAdd.EventItems.push(new EventItem(4));
我得到的推动是未定义的。
谢谢!
答案 0 :(得分:1)
添加var self = this;
作为Event
方法的第一行。没有它,您不小心将所有属性添加到容器对象而不是Event
对象。