2012-01-15 7 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이 모든 계산 된 속성의 기본값인지 여부에 대한 논의가있었습니다. http://jsfiddle.net/ebryn/9ZKSY/

+0

감사 :

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

는 여기 jsFiddle 예입니다! 너 락. –

+4

캐시 가능을 기본값으로 만드는 것에 대한 Github의 토론은 다음과 같습니다. https://github.com/emberjs/ember.js/issues/38 –

+1

이제 기본값 : http://emberjs.com/api/classes/Ember .ComputedProperty.html # method_cacheable –

관련 문제