我试图从WebSQL获取数据然后放入名为storeArr的数组中。但是,每次调试时,数组的长度都为0.我无法检测到此代码中的错误。
if(button == 1){
var compare = a + b + d + e + f + g;
var storeArr = [];
var duplicate = "";
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM RentalZ_', [], function (tx, sqlResultSet) {
var len = sqlResultSet.rows.length;
for (i = 0; i < len; i++){
var data = sqlResultSet.rows.item(i);
storeArr.push(data.property_type + data.rooms + data.rent + data.furniture + data.notes + data.name);
}
}, null);
});
console.log(storeArr.length);
for(i = 0; i < storeArr.length; i++){
if(storeArr[i] == compare){
duplicate = "YES";
break;
}
}
if(duplicate != "YES"){
console.log("Data Successfully Added!");
alert("added");
db.transaction(function (tx) {
tx.executeSql('INSERT INTO RentalZ_ (property_type, rooms, date_time, rent, furniture, notes, name) VALUES(?,?,?,?,?,?,?)',[a,b,c,d,e,f,g]);
});
} else {
alert("nan");
console.log("Duplicate Data Detected!");
}
}