Reputation: 4484
I'm using the knockout mapping plugin to map a collection of objects from the server to an observable array. I'd like to be able to subscribe to some change events on a few properties on those mapped objects. Can anyone point out what I'm doing wrong?
$.getJSON(apiUrl, function (data) {
ko.mapping.fromJS(data, {}, self.ReportTemplates);
for (var i = 0; i < self.ReportTemplates().length; i++) {
var reportTemplate = self.ReportTemplates()[i];
//try to subscriber here?
reportTemplate.VideoId.subscribe = function (a) {
alert(a);
};
}
});
Upvotes: 1
Views: 371
Reputation: 38382
You're using subscribe
wrong. You should be calling it and passing in your handler, i.e.
reportTemplate.VideoId.subscribe(function (a) {
alert(a);
});
Upvotes: 2