你能告诉我为什么当我从数据库中获取数据时我的价值会自己增加吗?实际上,我正在从电话间隙中的表中获取数据。但同时我还计算了另一个表中的元素数量。同时获取我自己增加的值并得到一个错误。项目索引超出范围。
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);
});
});
}
也检查我的评论.. !!