計算されたフィルタリングされたプロパティを作成するにはどうすればよいですか?
-
28-10-2019 - |
質問
私はこのようなものを持っています:
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 Computedプロパティに注意してください。
子供を使用している場合_filtered biewで...
{{#each content.children_filtered }}
hi
{{/each}}
私のアプリケーションはCPU @100%でハングアップします
私が間違っていることはありますか?アイテムのリストとフィルタリングされたアイテムのリストを備えたオブジェクトに従うべきより良いパターンはありますか?
解決
あなたの問題は、計算されたプロパティをとして設定する必要があることです cacheable
. 。それ以外の場合、その価値は、 #each
. 。かどうかについて議論がありました cacheable
すべての計算されたプロパティのデフォルトである必要があります。
children_filtered: function(){
return this.get("children").filterProperty("archived",false);
}.property("children").cacheable()
これがJSFiddleの例です: http://jsfiddle.net/ebryn/9zksy/
所属していません StackOverflow