繁体   English   中英

如何从查询函数获取结果驻留在另一个文件中? (JavaScript,phoneGap和Sqlite)

[英]How to get the result from a query function reside in another file? (Javascript, phoneGap and Sqlite)

我想将main.js文件与sqlite函数文件分开。 如何将查询结果获取到main.js(fr anotherFile.js)。

//In main.js
function getResult() {
    queryDB(); //how to get d result from queryDB() ?
}

// In anotherFile.js:
function queryDB(tx) {
    tx.executeSql('SELECT * FROM DEMO', [], onSuccess, onError);
}

function onSuccess(tx, results) {
    for (var i=0; i<result.length; i++) { 
        //what to put here, Array?
    }
}

谢谢。

//anotherFile.js:

function queryDB(tx, callbackMethod) {
    tx.executeSql('SELECT * FROM DEMO', [], callbackMethod, onError);
}

//main.js

function sendQuery() {
    queryDB(tx, queryResult);
}

function queryResult(tx, results) {
    for (var i=0; i<result.length; i++) { 

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM