2015-10-02 119 views
2

想象一下,我有一个包含2个属性的组件: 如何根据localID属性和Ember.computed.filterBy宏创建计算属性?Ember如何将变量传递给Ember.computed.filterBy

localID: 2, 

data: [ 
{ 
    id:1, 
    values: [1,2,3] 
}, 
{ 
    id:2, 
    values: [4,5,6] 
}, 
{ 
    id:3, 
    values: [7,8,9] 
}], 

我曾尝试:

filteredData: Ember.computed.filterBy('data', 'id', 'localID') // localID gets treated as a string 

filteredData: Ember.computed.filterBy('data', 'id', localID) // localID not defined 

filteredData: Ember.computed.filterBy('data', 'id', this.get('localID')) // 'this' not valid in this context.. 

filteredData: Ember.computed.filterBy('data', 'id', ${localID}) // etc.. 

似乎没有任何工作。当然,如果我输入静态值,我有它的工作原理,但我希望它引用在这种情况下LOCALID,因为它的其他财产将从控制器传递。

感谢您的帮助..

回答

1

重写你的财产

filteredData: function() { 
    return this.get('data').filterBy('id', this.get('localID')); 
}.property('[email protected]')