Javascript 余烬计算属性_super

Javascript 余烬计算属性_super,javascript,ember.js,Javascript,Ember.js,我想知道是否有办法获得计算属性的\u super 例如: controllers/core controller.js export default Controller.extend({ myAttribute: computed(function() { return { bar: this.get('bar') }; }); }); import CoreController from 'controllers/co

我想知道是否有办法获得计算属性的
\u super

例如:

controllers/core controller.js

export default Controller.extend({
    myAttribute: computed(function() {
        return {
            bar: this.get('bar')
        };
    });
});
import CoreController from 'controllers/core-controller';

export default CoreController.extend({
    myAttribute: computed(function() {
        let super = this.get('_super') //I'm trying to get the myAttribute object from the CoreController
        return merge(super, { foo: 'foo' });
    });
});
controllers/my controller.js

export default Controller.extend({
    myAttribute: computed(function() {
        return {
            bar: this.get('bar')
        };
    });
});
import CoreController from 'controllers/core-controller';

export default CoreController.extend({
    myAttribute: computed(function() {
        let super = this.get('_super') //I'm trying to get the myAttribute object from the CoreController
        return merge(super, { foo: 'foo' });
    });
});
最好的方法是什么


谢谢。

您可以在初始化期间定义属性:

export default CoreController.extend({
  defineMyAttribute: Ember.on('init', function() {
    const superValue = this.get('myAttribute');

    Ember.defineProperty(this, 'myProperty', Ember.computed(function() {
      return merge(superValue, { foo: 'foo' });
    }));
  })
})

警告:在初始化期间,您只能获得一次
superValue
。如果
myAttribute
具有依赖项,它可以重新计算,但它总是从要合并的超类中获取原始值,而不是更新的值。

您可以在初始化期间定义属性:

export default CoreController.extend({
  defineMyAttribute: Ember.on('init', function() {
    const superValue = this.get('myAttribute');

    Ember.defineProperty(this, 'myProperty', Ember.computed(function() {
      return merge(superValue, { foo: 'foo' });
    }));
  })
})

警告:在初始化期间,您只能获得一次
superValue
。如果
myAttribute
有依赖项,它可以重新计算,但它总是从要合并的超类中获取原始值,而不是更新的值。

您可以通过调用
this来实现。\u super(…参数)


在这个小游戏中还演示了:

您可以通过调用
this来实现。_super(…参数)


也在这个小游戏中演示了:

在我问这个问题之前,我先尝试了一下,但它不起作用。不知怎的,现在它运行良好,完美!在我问这个问题之前,我先尝试了一下,但它不起作用。不知怎的,现在它运行良好,完美!