Question

I'm having trouble when trying to set an observable property of an observable using Knockout. The line which has the error has been commented with the error. What am I doing wrong, how can I set that value?

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
});
Was it helpful?

Solution

try invoking the editedEvent observable first:

timelineViewModel.editedEvent().timelineId(0);

I got the same error initially in my test case, but that change did the trick for me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top