2012-01-15 26 views
8

私はこのようなものを持っている:計算されたフィルタリングされたプロパティを作成するにはどうすればよいですか?

Epic = Ember.Object.extend({ 
    children:[], 
    children_filtered: function(){   
     return this.get("children").filterProperty("archived",false); 
    }.property("children"), 
    init: function() { 
     this._super(); 
     this.set("children", Ember.ArrayController.create({content:[]})); 
     this.set("stories", Ember.ArrayController.create({content:[]})); 
    }, 
}); 

注children_filtered計算されたプロパティ。

私はビューにchildren_filtered使用する場合

は...

{{#each content.children_filtered }} 
    hi 
{{/each}} 

私のアプリケーションは、私が間違ってやっている100%

任意のアイデア@ CPUとハングアップ?アイテムのリストとフィルタリングされたアイテムのリストを持つオブジェクトのフォローアップには、より良いパターンがありますか?

答えて

12

計算されたプロパティをcacheableに設定する必要があるという問題があります。それ以外の場合、その値は#eachの各反復ごとに再計算されます。 cacheableがすべての計算されたプロパティのデフォルトであるべきかどうかについての議論がありました。

children_filtered: function(){   
    return this.get("children").filterProperty("archived",false); 
}.property("children").cacheable() 

ここjsFiddleの例です:http://jsfiddle.net/ebryn/9ZKSY/

+0

ありがとう!あなたは揺れる。 –

+4

cacheableをデフォルトにする方法についてのGithubの議論は、ここにあります:https://github.com/emberjs/ember.js/issues/38 –

+1

そしてこれがデフォルトです:http://emberjs.com/api/classes/Ember .ComputedProperty.html#method_cacheable –

関連する問題