简体   繁体   English

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

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

I wanted to separate my main.js file from my sqlite function file. 我想将main.js文件与sqlite函数文件分开。 How can I get the result of the query to the main.js (fr anotherFile.js). 如何将查询结果获取到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?
    }
}

thanks. 谢谢。

//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.

相关问题 Phonegap - 如何从索引页面调用另一个文件中的一个javascript函数? - Phonegap - How to call one javascript function in another file from index page? 获取sqlite选择查询javascript的结果 - get the result of an sqlite select query javascript (JavaScript) 如何从另一个 function 返回结果? - (JavaScript) How to return result from another function? 如何在phonegap javascript函数中返回结果? - how to return result in phonegap javascript function? 如何从具有phonegap数据库SQLite查询的内部函数返回值到外部函数 - how to return a value from inner function that have a phonegap database SQLite query to the outer function 如何在 javascript 上的另一个 js 文件中从 function 获取返回数据 - How to get return data from function in another js file on javascript 如何从javascript获取clone()函数的结果? - How to get the result of the clone() function from javascript? 如何从服务文件返回或导出函数 javascript 的结果以在另一个文件中使用 - How to return or export result of function javascript from service file to use in another file 如何从Java中的匿名函数获取结果? - How to get the result from an anonymous function in Javascript? 如何从 React Native 中的 SQLite 查询返回另一个 function 中的数据 - How to return data in another function from a SQLite query in React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM