我正在尝试编写一个函数来确定html5 websql db表是否为空。代码如下。我在那里发出警报,看看发生了什么。当此功能运行时,首先会弹出底部的警报。虽然该表为空,但返回值为false。
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;
}