Ember 组件中的修改方法
Modify method in Ember Component
在Discourse我要修改方法_dock
。修改代码将放在插件中。
这是该文件的简短片段:
export default Ember.Component.extend({
elementId: 'topic-progress-wrapper',
classNameBindings: ['docked', 'hidden'],
...
_dock() {
...
},
});
如何修改这个方法?我应该重新打开这个组件吗?它的语法是什么?
看看this and this指南。
您需要创建一个新组件,如下所示:
// components/my-discourse-component.js
import MyDiscourseComponent from 'discourse/components/topic-progress';
MyDiscourseComponent.extend({
// Here you can extend the function. Don't forget
// this._super(...arguments) if you want to use the original function.
});
MyDiscourseComponent.reopenClass({
// Here you can completly override the function.
});
export default MyDiscourseComponent;
并在您的模板中使用 {{my-discourse-component}}
。
或者您可以将插件的代码复制到混合宏中,然后使用该混合宏简单地扩展您的新组件。
在Discourse我要修改方法_dock
。修改代码将放在插件中。
这是该文件的简短片段:
export default Ember.Component.extend({
elementId: 'topic-progress-wrapper',
classNameBindings: ['docked', 'hidden'],
...
_dock() {
...
},
});
如何修改这个方法?我应该重新打开这个组件吗?它的语法是什么?
看看this and this指南。 您需要创建一个新组件,如下所示:
// components/my-discourse-component.js
import MyDiscourseComponent from 'discourse/components/topic-progress';
MyDiscourseComponent.extend({
// Here you can extend the function. Don't forget
// this._super(...arguments) if you want to use the original function.
});
MyDiscourseComponent.reopenClass({
// Here you can completly override the function.
});
export default MyDiscourseComponent;
并在您的模板中使用 {{my-discourse-component}}
。
或者您可以将插件的代码复制到混合宏中,然后使用该混合宏简单地扩展您的新组件。