我有一個小提琴http://jsfiddle.net/kristaps_petersons/9wteJ/2/它加載3個對象,並在視圖中顯示它們。數據顯示正常,但在展示之前我無法對其進行過濾。 這Ember.Controller數組內容過濾
nodes: function(){
this.get('controller.content').filter(function(item, idx, en){
console.log('should log this atleast 3x')
})
return this.get('controller.content')
}.property('controller.content')
方法被調用時,在值數組模板迭代,但它從來沒有進入到循環和打印console.log('should log this atleast 3x')
這是爲什麼?
我改變了你說的代碼,但它仍然沒有進入循環。檢出小提琴 http://jsfiddle.net/kristaps_petersons/9wteJ/11/ 我添加了兩個console.log行 'console.log('BEFORE應該記錄這至少3倍')' 'console.log('AFTER應該至少記錄這3行')' 它會像以前一樣打印這些行,但不會進入循環。儘管所有節點都返回 – Kristaps
添加'cacheable()'也沒有解決 – Kristaps
我最近一直在爲Ember ArrayController進行實時篩選。它建立在這個例子上。請參閱http://jsbin.com/UvePomO/4/edit?html,js輸出 – adroitec