我有一个按钮对话框。点击按钮后,该按钮会调用一个异步方法,根据发布的数据是否有效返回true或false。 点击事件调用下面的方法。 现在,问题是在执行回调函数之前调用closeDialog! 我该如何做这项工作?等待异步通话完成 - 太晚
感谢
close: function (srcCmd) {
var closeResult = true;
asyncThing(function(result) {
if (result)
closeResult = true;
else
closeResult = false;
});
if (closeResult !== false) {
this.closeDialog();
}
},
把'this.closeDialog()'放在回调中(第一个'if'条件)。你还需要绑定'this'。 – ftor
可能的重复[如何从异步调用返回响应?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas
https://jsfiddle.net/rayon_1990/tzzze97s/ – Rayon