javascript - Ember 计算属性 _super

标签 javascript ember.js

我想知道是否有办法获取计算属性的 _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' });
    });
});

最好的方法是什么?

谢谢。

最佳答案

您可以通过调用 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' });
    });
});

也在这个 twiddle 中演示:https://ember-twiddle.com/dba33b9fca4c9635edb0

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

相关文章:

javascript - Facebook 喜欢以 0 宽度和 0 高度呈现的按钮?

javascript - Google Charts 上升 1,不连续

javascript - HTML 中的 UINavigationController 类型菜单

ember.js - 如何在EmberJS中设置 "ENV"变量?

javascript - 在 EmberJS 中,外部 JS 文件应该放在哪里?

javascript - 带有脚本的按钮在第二次单击后发送带有值的回发

javascript - Facebook 点赞按钮不喜欢我的代码

javascript - Emberjs 更新/观察者/运行循环

javascript - 加载时重置 Ember 组件

ember.js - 无法进行简单的验收测试以正常运行