1

有人可以告诉我为什么这不起作用吗?

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));

我得到那个推送是未定义的。

谢谢!

4

1 回答 1

1

添加var self = this;Event方法的第一行。没有它,您会不小心将所有属性添加到容器对象而不是Event对象中。

于 2013-05-29T17:42:35.127 回答