我正在尝试编写一个函数来确定 html5 websql db 表是否为空。代码如下。我在那里放了警报,看看发生了什么。当这个函数运行时,底部的警报首先弹出。虽然表是空的,但返回值是假的。
function tableisempty() {
tf = false;
query = "SELECT * FROM OLL;";
localDB.transaction(function(transaction){
transaction.executeSql(query, [], function(tx, results){
if (results.rows.length == 0) {
tf = true;
alert ("table has "+results.rows.length+" rows. returning "+tf);
} else {
tf = false;
alert ("table is not empty. returning "+tf);
}
}, errorHandler);
});
alert ("return value is " + tf);
return tf;
}