Ember扩展组件计算属性?

时间:2018-05-04 19:37:53

标签: javascript ember.js

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

父:

Ember.Component.extend({
  items: computed(function() {
    return ['a', 'b'];
  })
})

子:

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

1 个答案:

答案 0 :(得分:1)

是的!使用_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

相关问题