我写了以下内容function来检查我的HTML5 openDatabase表是满的还是空的:
var that = this;
that.db = openDatabase('dbname', '1.0', "description", 1024 * 1024);
that.tableFilled = function( tableName ) {
that.db.transaction(function ( tx ) {
tx.executeSql('SELECT * FROM ' + tableName, [],
function success( c, results ) {
return ( results.rows.length > 0 ? true : false );
},
function fail() {
console.log('FAiL');
}
);
});
};
我正在尝试return或值。truefalsetableFilled()
实际上that.tableFilled('tableName')返回undefined。
我最终想要实现的是:
if ( that.tableFilled('tableName') ){
// ...
}
有没有一种方法可以return在true不使用回调false的情况下对父函数赋值?tableFilled()