我想知道是否有一种获得计算属性的_super的方法?
例如:
controllers/core-controller.js
export default Controller.extend({
myAttribute: computed(function() {
return {
bar: this.get('bar')
};
});
});controllers/my-controller.js
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' });
});
});这样做最好的方法是什么?
谢谢。
发布于 2016-02-07 21:38:07
您可以通过调用this._super(...arguments)来做到这一点
import CoreController from 'controllers/core-controller';
export default CoreController.extend({
myAttribute: computed(function() {
let superValue = this._super(...arguments);
return merge(superValue, { foo: 'foo' });
});
});也是在这个圈子里降级的:https://ember-twiddle.com/dba33b9fca4c9635edb0
发布于 2016-02-07 20:50:28
您可以在初始化期间定义该属性:
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' });
}));
})
})警告:在init期间,您只会得到一次superValue。如果myAttribute有依赖项,它可以重新计算,但是它总是从超类获得要合并的原始值,而不是更新的值。
https://stackoverflow.com/questions/35258849
复制相似问题