2

Discourse我想修改方法_dock。修改代码将放在插件中。

这是该文件的简短片段:

export default Ember.Component.extend({
  elementId: 'topic-progress-wrapper',
  classNameBindings: ['docked', 'hidden'],

  ...
  _dock() {
    ...
  },

});

如何修改此方法?我应该重新打开这个组件吗?它的语法是什么?

4

1 回答 1

1

看看这个这个指南。您需要创建一个新组件,如下所示:

// 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}}在您的模板中使用。

或者您可以将插件的代码复制到一个 mixin 中,然后使用该 mixin 简单地扩展您的新组件。

于 2016-09-11T16:36:39.410 回答