保持执行For循环而不中断并继续

时间:2013-04-26 11:17:42

标签: jquery for-loop execution web-sql

我想继续执行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函数并等待其返回值,然后继续第二个请求。

0 个答案:

没有答案