Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将具有phonegap数据库SQLite查询的内部函数的值返回到外部函数_Javascript_Jquery_Html_Cordova_Android Sqlite - Fatal编程技术网

Javascript 如何将具有phonegap数据库SQLite查询的内部函数的值返回到外部函数

Javascript 如何将具有phonegap数据库SQLite查询的内部函数的值返回到外部函数,javascript,jquery,html,cordova,android-sqlite,Javascript,Jquery,Html,Cordova,Android Sqlite,这是我的密码 hasSubAcc = function(accPid) { $.mobile.eazydb.transaction(function(tx) { tx.executeSql('SELECT * FROM Account WHERE Account_Parent_ID="'+accPid+'"', [], function(tx, rs){ if(rs.rows.length == 0) {

这是我的密码

hasSubAcc = function(accPid) {
    $.mobile.eazydb.transaction(function(tx) {
        tx.executeSql('SELECT * FROM Account WHERE Account_Parent_ID="'+accPid+'"', [],
            function(tx, rs){
                if(rs.rows.length == 0) {
                    return false;
                } else {
                    return true;
                }
        });
    });
}
以及

alert(hasSubAcc(accid));

此警报打印未定义的内容。这个代码有什么问题。任何解决方案都可以。谢谢。

问题非常清楚,因为您在函数中使用了繁重的进程(即数据库),所以jquery在与主线程平行的单独线程中运行此函数。现在,在这种情况下,您的值将始终未定义

您可以创建一个全局变量
var hasSubAcc=-1检查条件后立即执行

if(rs.rows.length == 0) {
                    hasSubAcc=0;
                } else {
                    hasSubAcc=1;
                }
现在使用

setTimeout(function(){
alert(hasSubAcc);

},500);

or

while(hasSubAcc==-1){
//do nothing
}
alert(hasSubAcc);

有什么错误吗?检查错误日志。没有错误。它只打印未定义的和proceedYou可以将hasSubAcc代码放入函数中,并从executeSQL()回调调用它