NullReference
NullReference

Reputation: 4484

Is it possible to iterate through mapped observable array and subscribe?

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

Answers (1)

bradley.ayers
bradley.ayers

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

Related Questions