我将闭包动作传递给我的组件,如下所示:
{{deployment-timeline loadMoreDeployments=(action "loadMoreDeployments")}}
我应该如何在我的组件中调用它?
actions:{
loadMoreDeployments(){
// which one of the following three invocations is best?
this.attrs.loadMoreDeployments();
this.get('loadMoreDeployments')();
this.loadMoreDeployments();
}
}
答案 0 :(得分:2)
你应该做
this.get('loadMoreDeployments')();
或
import {get} from '@ember/object';
...
get(this, 'loadMoreDeployments')();
从未引入attrs
的使用,不建议使用带点符号访问ember对象上的属性。
修改:With ember 3.1
(currently in beta) we will get support for dot notation for getters (no setters yet, and not for proxy objects).这意味着您可以从ember 3.1
安全使用:
this.loadMoreDeployments();