0

尝试使用 Knockout 设置可观察对象的可观察属性时遇到问题。有错误的行已用错误注释。我做错了什么,我该如何设置该值?

function Event() {
    "use strict";
    var self = this;
    self.timelineId = ko.observable(); 
}

function TimelineViewModel() {
    "use strict";
    var self = this;

    self.editedEvent = ko.observable(new Event());
}

$(document).ready(function () {
    var timelineViewModel = new TimelineViewModel();
    ko.applyBindings(timelineViewModel);

    timelineViewModel.editedEvent.timelineId(0); //Error: TypeError: timelineViewModel.editedEvent.timelineId is not a function
});
4

1 回答 1

1

尝试首先调用editedEvent observable:

timelineViewModel.editedEvent().timelineId(0);

我最初在我的测试用例中遇到了同样的错误,但是这个改变对我有用!

于 2013-09-05T21:59:59.060 回答