gpt4 book ai didi

javascript - Ember 扩展组件计算属性?

转载 作者:行者123 更新时间:2023-11-30 20:32:35 25 4
gpt4 key购买 nike

我有一个父组件 Parent 和扩展 Parent 的 Child 组件。在 Parent 中有一个返回数组的计算属性 items。有没有办法在子组件中包含 items ,它将返回父数组中的元素和其他元素,例如

家长:

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 .

关于javascript - Ember 扩展组件计算属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50182042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com