我将闭合动作传递给组件,如下所示:

{{deployment-timeline loadMoreDeployments=(action "loadMoreDeployments")}}


我应该如何在我的组件中调用它?

actions:{
  loadMoreDeployments(){
    // which one of the following three invocations is best?
    this.attrs.loadMoreDeployments();
    this.get('loadMoreDeployments')();
    this.loadMoreDeployments();
  }
}

最佳答案

你应该做

this.get('loadMoreDeployments')();


要么

import {get} from '@ember/object';
...
get(this, 'loadMoreDeployments')();


不可能引入attrs的用途,并且不建议使用点符号来访问余烬对象的属性。

编辑:With ember 3.1 (currently in beta) we will get support for dot notation for getters (no setters yet, and not for proxy objects).这意味着从余烬3.1可以安全使用:

this.loadMoreDeployments();

09-06 01:14