我不知道如何进行两个单独的异步调用并使 call1 等待 call2 完成,一直在查找,我想我需要使用回调或承诺,但就是不明白,有没有人有链接到一个简单的解释?或者任何人都可以建议如何调整我的代码?
我已经“简化”了代码。
如何确保仅在constructButton 完成后才读取下一条记录?
function justAfunction(){
var query = "SELECT * FROM trlydp where tdrexr = " + route + " order by tdrseq;";
try {
localDB.transaction(function(transaction){
transaction.executeSql(query, [], function(transaction, results){
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
constructButton();
}
}, function(transaction, error){
updateStatus("Error: " + error.code + "<br>Message: " + error.message);
});
});
}
catch (e) {
updateStatus("Error: Unable to select data from the db " + e + ".");
}
}
function constructButton(){
disabled = false;
var query = 'SELECT * FROM trlylp';
//alert(query);
try {
localDB.transaction(function(transaction){
transaction.executeSql(query, [], function(transaction, results){
alert(results.rows.length);
if (results.rows.length != 0) {
disabled = true;
}
}, function(transaction, error){
updateStatus("Error: " + error.code + "<br>Message: " + error.message);
});
});
}
catch (e) {
updateStatus("Error: Unable to select data from the db " + e + ".");
}
}