为什么在从sqlite获取数据时我自己增加了这个值? [英] why the value i increase by own i this loop while fetching the data from sqlite?

查看:69
本文介绍了为什么在从sqlite获取数据时我自己增加了这个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能否告诉我为什么当我从数据库中获取数据时i的值增加了。实际上我从手机间隙中的表中获取数据。但是我还计算了另一个表中的元素数量。而获取i的值会增加自己并获得错误.Item索引超出范围。

can you please suggest me why the value of i increase by own when i am fetching data from data base . Actually i am fetching data from table in phone gap .But along with i also count the number of elements in another table .while fetching the value of i increase by own and getting an error..Item index is out of range.

function getallTableData(tx) {

   tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
}

    function querySuccess(tx, result) {

        var len = result.rows.length;
        var countDoument=0
        $('#folderData').empty();
        for (var i = 0; i < len; i++) {

             alert(i)  // here value is i =0

             test1=result.rows.item(i).CaseName;



    Test1(test1,function(result_count){
    countDoument=result_count;   // here it count value
    alert(result_count+"result_count")  //alert is correct count value
    alert(i+"i"); //here i comes 1 why ? it should be 0

    $('#folderData').append(
                    '<li class="caseRowClick" id="' + result.rows.item(i).id + '" data-rel="popup" data-position-to="window">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>' + result.rows.item(i).CaseName +countDoument+'</h2>' + '<p>' + result.rows.item(i).TextArea + '</p>' + '<p>' + result.rows.item(i).CaseDate + '</p>' + '</a>' +
                     '<span class="ctrl togg"><fieldset data-role="controlgroup" data-type="horizontal" data-mini="true" ><button class="edit button_design">Edit</button><button class="del button_design">Delete</button></fieldset><span>'+'</li>'
                    );

        });

       $('#folderData').listview('refresh');




    }


    }

    function Test1(test, callBack){
        var x;
        db.transaction(function (tx) {
                $yoursql = 'SELECT * FROM  "'+test+'" ';
                tx.executeSql($yoursql, [], function (tx, results) {
                    x = results.rows.length  + "TableName" + test;
                    callBack(x);
                });
        });

    }



检查我的评论.. !!


Check my comments also..!!

推荐答案

' #folderData')。empty();
for var i = 0 ; i < len; i ++){

alert(i) // 此处值为i = 0

test1 = result.rows.item(i).CaseName;



Test1(test1,function(result_count){
countDoument = result_count; // < span class =code-comment>此处计算值
alert(result_count + result_count // 警报是正确的计数值
alert(i + i); // 这里我来1为什么?它应该是0
('#folderData').empty(); for (var i = 0; i < len; i++) { alert(i) // here value is i =0 test1=result.rows.item(i).CaseName; Test1(test1,function(result_count){ countDoument=result_count; // here it count value alert(result_count+"result_count") //alert is correct count value alert(i+"i"); //here i comes 1 why ? it should be 0


' #folderData')。append(
' < li class =caseRowClickid =' + result.rows.item(i).id + ' data-rel =弹出data-position-to =window>' + < a href =#>' + ' < img src =img / Blue-Folder.png>' + ' < span class =code-string>< h2>' + result.rows.item(i).CaseName + countDoument + ' < / h2>' + ' < p>' + result.rows.item(i).TextArea + ' < / p>' + < span class =code-string>' < p>' + result.rows.item(i).CaseDate + ' < / p>' + ' < / a>' +
' < span class =ctrl togg>< fieldset data-role =cont rolgroupdata-type =horizo​​ntaldata-mini =true>< button class =edit button_design>编辑< / button>< button class =del button_design>删除< / button> < / fieldset>< span>' + ' < / li>'
);

});
('#folderData').append( '<li class="caseRowClick" id="' + result.rows.item(i).id + '" data-rel="popup" data-position-to="window">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>' + result.rows.item(i).CaseName +countDoument+'</h2>' + '<p>' + result.rows.item(i).TextArea + '</p>' + '<p>' + result.rows.item(i).CaseDate + '</p>' + '</a>' + '<span class="ctrl togg"><fieldset data-role="controlgroup" data-type="horizontal" data-mini="true" ><button class="edit button_design">Edit</button><button class="del button_design">Delete</button></fieldset><span>'+'</li>' ); });


' #foliteData ')。listview(' refresh');




}


}

函数Test1(test,callBack){
var x;
db.transaction(function(tx){
('#folderData').listview('refresh'); } } function Test1(test, callBack){ var x; db.transaction(function (tx) {


这篇关于为什么在从sqlite获取数据时我自己增加了这个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆