侦听新添加的属性对计算功能
问题描述:
我有以下对象:侦听新添加的属性对计算功能
{
types: ["Type A", "Type B", "Type C"],
colours: ["Red", "Blue", "Black"]
}
我作为参数发送到组件
export default Ember.component.extend({
tableContent: function(){
const keys = Object.keys(this.get('config'));
if (keys.length > 1){
let array = [];
keys.shift();
keys.forEach((element) => {
array.pushObject({name: element});
});
return array;
}
}.property('config')
我希望能够侦听更改时创建一个新的补充。例如:
{
types: ["Type A", "Type B", "Type C"],
colours: ["Red", "Blue", "Black", "Yellow"].
lang: ["en","fr","es"]
}
我试过使用.property('config。@ each'),但它不会工作。
任何想法? 谢谢。
答
config
是一个对象,所以[email protected]
会奏效。 您可以侦听所有[email protected]
[email protected]
[email protected]
或者它可以缩短到这样的事情config.{types,colours,lang}[email protected]
参见:https://guides.emberjs.com/v2.16.0/object-model/computed-properties-and-aggregate-data/