[英]How to (if possible) call an Ember Action in a Javascript procedure or function?
My question is for an Ember Action defined in the same file as the Javascript procedure, in Ember 2.1.我的问题是在 Ember 2.1 中与 Javascript 过程在同一文件中定义的 Ember 操作。
For example, as here where the ember code where we would like to call to myAction outside of the "export" zone:例如,在这里,我们希望在“导出”区域之外调用 myAction 的 ember 代码:
export default Component.extend({
actions: {
myAction() {
}
}
});
function test(x) {
CALL TO myAction HERE
return(3x);
}
In modern ember actions are just functions, so you can just call them:在现代 ember 中,动作只是函数,所以你可以调用它们:
export default class MyComponent extends Component {
myFunc() {
this.myAction(); // this just works
}
@action
myAction() {
}
}
in older embers classic classes there is send
or alternatively you can access the action and .call
it.在较旧的 embers 经典课程中有
send
或者您可以访问该操作并.call
它。
export default Component.extend({
myFunc() {
this.send('myAction'); // this calls the action
this.actions.myAction.call(this); // this calls the action
}
actions: {
myAction() {
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.