我的代码中有等待功能完成的问题:
function myfucntion1() { .... // call sql adapter to get data from database onSuccess:callfunctionsucc, onFailure:calfunctionfail .... } function callfunctionsucc(data) { //foreach in data // call myfunction3(item) } function myfunction3(item) { .... // call sql adapter to get data from database onSuccess:callfunctionsucc2, onFailure:calfunctionfail2 .... } function callfunctionsucc2(data) { //foreach in data //and set data to myarr is my global variable } function myfunction2() { // access to myarr and process it }
当我打电话时:
var myarr = []; myfucntion1(); myfunction2();
我的问题出在 myfunction2(),myarr = 0,因为当我运行 myfunction1 时它调用 callfunctionsucc,但是当离开 myfunction1 时,在 callfunctionsucc 期间调用 myfunction2 尚未完成。我如何等待 callfunctionsucc 完成然后调用 myfunction2 ?谢谢你的帮助