2012-07-02 42 views
1

示例代碼:觀察整個ArrayProxy

var Day = Ember.Object.extend({ 
    date:null, 
    activities:null, // is set to an Em.ArrayProxy in instantiation 
    historicalSection:function(){ 
    return this.get('activities').filterProperty('inHistoricalSection', true); 
    }.property('activities').cacheable() 
}); 

當 '活動' 被設置爲ArrayProxy, 'historicalSection' 計算的屬性,都會計算。但是,當'activities'處的ArrayProxy被更新時(即其長度發生變化),'historicalSection'屬性不會更新。

任何想法,爲什麼?

回答

5

當您在activites上綁定計算屬性時,這意味着它將在您爲activities設置新值時更新,因此在初始時和僅在調用set('activities', newArrayProxy)時才更新。

您可以使用[email protected]activities.length爲綁定屬性,觀察長度變化

+1

非常感謝。 activities.length爲我工作。 – Rajat