Ember 扩展组件计算 属性?
Ember extend component computed property?
我有一个 parent 组件 Parent 和扩展 Parent 的 Child 组件。
在 Parent 中有一个 属性 items
的 return 数组。有没有办法在 Child 组件中包含 items
,这将 return 来自 parent 数组的元素和其他元素,例如
Parent:
Ember.Component.extend({
items: computed(function() {
return ['a', 'b'];
})
})
Child:
Parent.extend({
items: computed(function() {
// I want to add some more elements to parent property
// so this should return ['a', 'b', 'c', 'd']
return this.get('items').concat(['c', 'd']);
})
});
目前我得到 Maximum call stack size exceeded
。
是的!使用 _super
:
Parent.extend({
items: computed(function() {
// I want to add some more elements to parent property
// so this should return ['a', 'b', 'c', 'd']
return this._super('items').concat(['c', 'd']);
})
});
这是一个有效的 twiddle。
我有一个 parent 组件 Parent 和扩展 Parent 的 Child 组件。
在 Parent 中有一个 属性 items
的 return 数组。有没有办法在 Child 组件中包含 items
,这将 return 来自 parent 数组的元素和其他元素,例如
Parent:
Ember.Component.extend({
items: computed(function() {
return ['a', 'b'];
})
})
Child:
Parent.extend({
items: computed(function() {
// I want to add some more elements to parent property
// so this should return ['a', 'b', 'c', 'd']
return this.get('items').concat(['c', 'd']);
})
});
目前我得到 Maximum call stack size exceeded
。
是的!使用 _super
:
Parent.extend({
items: computed(function() {
// I want to add some more elements to parent property
// so this should return ['a', 'b', 'c', 'd']
return this._super('items').concat(['c', 'd']);
})
});
这是一个有效的 twiddle。