【问题标题】:Is it possible to iterate through mapped observable array and subscribe?是否可以遍历映射的可观察数组并订阅?
【发布时间】:2013-01-04 21:33:34
【问题描述】:

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

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

【问题讨论】:

    标签: knockout.js knockout-mapping-plugin


    【解决方案1】:

    你用错了subscribe。您应该调用它并传入您的处理程序,即

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-30
      • 2018-11-26
      • 2019-06-19
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多