0
JSBin Example爲什麼'數組'被傳遞給過濾器函數?
在以下代碼中,「陣列」是簡單地一個整數數組,「項目」是對象的列表,和「coprop」是「的項目」使用「陣列」所計算的過濾器(其可以改變)來決定「項目」中的哪些元素屬於「coprop」。
想要的結果就是'數組'中'值'的'項目'的那些元素。
實際結果是當'數組'元素(除了元素的'items'之外)因爲某種原因被傳遞給過濾函數時出現javascript錯誤。這會觸發'typeerror:i.get不是函數'消息。
array: [ 4, 5, 6 ],
items: function() {
return this.get('store').peekAll('item');
}.property(),
coprop: Ember.computed.filter('items', function(i,idx,ary) {
console.log('i = ' + i);
return this.get('array').isAny(i.get('value'));
}).property('items','array')
請注意這是一個簡單的例子來說明這個問題。過濾功能比這裏顯示的更復雜,但這確實顯示了相當清楚的問題。
實際輸出
"i = <App.Thing:ember409:1>"
"i = <App.Thing:ember410:2>"
"i = <App.Thing:ember411:3>"
"i = <App.Thing:ember412:4>"
"i = 4"
"error"
"TypeError: i.get is not a function
的課題
爲什麼 '陣列' 被傳遞給過濾器功能作爲要素來過濾?
如何確保'coprop'將在'數組'更改時更新?
完美!非常感謝! – EdwinW