2013-12-19 243 views
0

我很嶄新的燼,並試圖編寫一個計算屬性,檢查用戶是否在線,基於他們的'狀態'屬性,在用戶模型中定義,然後返回網上用戶數的統計。這就是我一直在嘗試,這是不working-基於模型屬性的灰燼計算屬性

onlineUsers: function() { 
    return this.get("model").filterBy("state", "online").get("model.length"); 
}.property("'model.[]'"), 

這是我的用戶模型 -

App.User = DS.Model.extend({ 
    name : DS.attr('string'), 
    email : DS.attr('string'), 
    state : DS.attr('string'), 
    subjects : DS.hasMany('subject')  
}); 

任何人都可以指出我在做什麼錯?

回答

2

您需要使用[email protected]

onlineUsers: function() { 
    return this.get("model").filterBy("state", "online").get("length"); 
}.property("[email protected]"), 

而且model.length到底不行,因爲filterBy的結果是一個新的數組,並希望該數組的長度。

+0

完美的作品,非常感謝。 – bookthief