AI助手支持GPT4.0
如何解决函数里异步调用问题?How to solve the problem of asynchronous calls in functions?
如何解决函数里异步调用问题?
test:async function(){
var that=this;
console.log('0');
const p=await new Promise(function(resolve,reject){
that.a();
resolve();
})
console.log('2');
},
a:function(){
wx.showModal({
showCancel: false,
confirmText:'确定',
content:'1',
title:'提示',
success:function(res){
if(res.confirm){
console.log('1');
}
}
})
如何在函数里调用另一个函数?目的是按顺序执行输出012,我试过直接将wx.showModal放到Promise里是可以按顺序输出的。
test:async function(){ var that=this; console.log('0'); const p=await new Promise(function(resolve,reject){ that.a(); resolve(); }) console. log('2'); }, a: Function() {Wx. Showmodal ({showcancel: false, confirmetext: 'OK', content: '1', Title: 'prompt', success: function (RES) {if (res.confirm) {console. Log ('1 ');}}}) How to call another function in a function? The purpose is to execute output 012 in sequence. I tried to directly convert Wx Showmodal can be output in order when it is put into promise.
test:async function(){ var that=this; console.log('0'); const p=await this.a() console.log('2'); }, a:async function(){ let res = await wx.showModal({ showCancel: false, confirmText:'确定', content:'1', title:'提示', }) if(res.confirm){ console.log('1'); }}