在组件内调用闭包操作的正确方法是什么?
What is the proper way to invoke a closure action inside a component?
我像这样将闭包操作传递到我的组件中:
{{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
的使用,并且不建议使用点表示法在 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();
我像这样将闭包操作传递到我的组件中:
{{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
的使用,并且不建议使用点表示法在 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();