Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 首先执行sendAction()_Javascript_Ember.js - Fatal编程技术网

Javascript 首先执行sendAction()

Javascript 首先执行sendAction(),javascript,ember.js,Javascript,Ember.js,所以我有这样的想法: function() { this.sendAction("myAction"); this.doSomething(); } 如何使“myAction”中的代码在此.doSomething()之前首先执行?您可以使this.sendAction运行回调以运行this.doSomething 像这样: this.sendAction = function(action, callback) { console.log(action);

所以我有这样的想法:

function() {  
    this.sendAction("myAction");
    this.doSomething();
}  

如何使“myAction”中的代码在此.doSomething()之前首先执行?

您可以使
this.sendAction
运行回调以运行
this.doSomething

像这样:

this.sendAction = function(action, callback) {
    console.log(action);
    callback();
}

this.sendAction('myAction', this.doSomething);

或者像锁建议的那样承诺。

简单的回答是你不能。如果您使用了一个关闭操作,并且它返回了一个承诺,那么您可以在继续之前等待它得到解决。不过,您可能不想覆盖这个。sendAction。您将在父组件的操作哈希中调用回调。