1

我想保持 for 循环的执行,直到里面的函数返回值,但是我的代码中的问题首先是当我签入调试器时,for 循环直接从 5 开始而不是 0,其次在它返回第一个值之前第二个请求是发送。我不想使用超时功能

我正在使用 Jquery 1.9.1 和 web-SQL。

function MakeSyncCall(rdosync) {
$('#hdrProgress').show();
$('#contentProgress').show();
var db = CreateDB();
var query = '';
var row = '';
query = "Select * From " + tablename + " order by ord_key";
db.transaction(populateDB, errorDB, successDB);
function populateDB(tx) {
    tx.executeSql(query, [], function (tx, results) {
        var result = [];
        var len = results.rows.length;

        debugger;
        if (len > 0) {
            for (var iv = 0; iv < len; iv++) {
                var row = results.rows.item(iv);
                rdosync = row['ord_key'];

                  var ReturnedValue=  ForLoop(rdosync);

            } //FOR LOOP
        } ///Main if
        else {
            alert('No Records to Sync');
            $('#hdrProgress').hide();
            $('#contentProgress').hide();
        }
    });
}
function errorDB(err) {
    alert("Error processing MakeSyncCall: " + err.message);

}
function successDB() {

}

}



function ForLoop(rdosync) {
alert(rdosync);
var tablename = 'SyncCheck';
var arrcolumnName = ['ord_key', 'SpecialInstruction', 'Interview', 'RoofModule',         'FireProtection'];
CreateTableWithDB(tablename, arrcolumnName);
query = "Select * From " + tablename + " where SpecialInstruction ='Y' and Interview=   'Y' and RoofModule ='Y' and FireProtection= 'Y' and ord_key = ?";

db.transaction(populateDB, errorDB, successDB);
function populateDB(tx) {
    tx.executeSql(query, [rdosync], function (tx, results) {
        var result = [];
        var len = results.rows.length;
        debugger;
        if (len > 0) {
            return row['ord_key']

        }
        else {
            alert(rdosync + " cannot be sync.Please complete all sections");
            $('#hdrProgress').hide();
            $('#contentProgress').hide();
        }
    });
}
function errorDB(err) {
    alert("Error processing MakeSyncCall: " + err.message);
    $('#hdrProgress').hide();
    $('#contentProgress').hide();
}
function successDB() {

}


}

在此,我想使用其参数执行 forloop 函数并等待其返回值,然后继续执行第二个请求。

4

0 回答 0