我有下面的代码,但是当它在语句中items.push
时不起作用。如果在结束之前if
取消注释该行,则按预期工作。}
items.push
for (i = 0; i < len; i += 1) {
row = resultexpense.rows.item(i);
t.executeSql('SELECT * FROM expensepayments WHERE Barcode = ?',
[row.barcode],
function(t, resultpaid) {
var myrowpaid,
myrowpaidlen;
myrowpaidlen = resultpaid.rows.length;
alert(myrowpaidlen); //alerts 1
if (myrowpaidlen > 0){
myrowpaid = resultpaid.rows.item(0);
alert(row.amount); //alerts 90
alert(myrowpaid.Amount); //alerts 50
if (row.amount > myrowpaid.Amount){
alert(row.amount- myrowpaid.Amount); //alerts 40
items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}
} else {
items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}
});
// items.push('<li><a href="#displayexpense" data-description="' + row.description + '" data-buildingcode = "' + row.buildingcode + '" data-barcode="' + row.barcode + '" data-amount="' + row.amount + '" data-buildingaddress="' + row.buildingaddress + '">' + row.description + '</a></li>');
}