Look at the form$.messager.confirm is an asynchronous call, you can wrap this call with a layer of promise;
function a(a,b) {
return new Promise(function(resolve, reject) {
$.messager.confirm('xxx','xx',function(r){
if (r) {
b = 1;
} else{
b = 2;
}
resolve(b);
});
});
}
The callback function is executed after your main function is executed, which means that you must first have two parameters, xxx and xx, and then the callback is executed. There is nothing wrong with your function.
The result of the callback function can only be sent out using the callback function.
Look at the form
$.messager.confirm
is an asynchronous call, you can wrap this call with a layer ofpromise
;When calling
a
, you can call it as followsThe callback function is executed after your main function is executed, which means that you must first have two parameters, xxx and xx, and then the callback is executed. There is nothing wrong with your function.