Knockout计算var不解雇订阅

时间:2016-07-23 21:25:10

标签: javascript mvvm knockout.js

不确定为什么订阅不会针对计算变量触发。有什么想法吗?

                self.TeamFilter        = ko.observableArray(["PWx","FRT"]);
                self.FilteredQueueList = ko.pureComputed(() => {
                    console.log('computing..');
                    let teamsArray = self.QueueListCached();          
                    return ko.utils.arrayFilter(teamsArray, (team) => {
                        let toFilter = false;

                        TeamFilter().forEach((filterText, idx) => {
                            toFilter = toFilter || (team.queue_name).indexOf(filterText) > -1;
                        });
                        console.log('computed');
                        return toFilter;
                    });
                }).extend({
                    notify: 'always'
                });

                self.FilteredQueueList.subscribe((newQueueList) => {
                    //self.QueueList.removeAll();
                    console.log('FilteredQueueList changed!');
                    //self.QueueList(self.FilteredQueueList());
                    //console.log(JSON.stringify(newQueueList, null, 2));
                });

计算出的回调中的console.logs被触发了。所以我知道计算变量正在创建。在这种情况下,我只是过滤一个Observable数组。

但订阅console.log不会触发,也不确定是什么问题。

0 个答案:

没有答案