是否可以遍历映射的可观察数组并订阅? [英] Is it possible to iterate through mapped observable array and subscribe?

查看:67
本文介绍了是否可以遍历映射的可观察数组并订阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用敲除映射插件将服务器中的对象集合映射到可观察的数组.我希望能够订阅那些映射对象的一些属性上的一些更改事件.谁能指出我做错了什么?

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

推荐答案

您使用的subscribe错误.您应该调用它并传递您的处理程序,即

You're using subscribe wrong. You should be calling it and passing in your handler, i.e.

reportTemplate.VideoId.subscribe(function (a) {
    alert(a);
});

这篇关于是否可以遍历映射的可观察数组并订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆