使用 WebSQL 回调(Phonegap)
我正在使用 Phonegap 和 Phonegap 编写一个应用程序。煎茶触摸。我有带有 Sencha 接口的 viewport.js 文件和带有所有数据库和请求功能的databasesFunctions.js 文件。
我想在 viewport.js 中调用这一行:
if(launchRequest('SELECT * from items',nombreItems)) alert('there are items');
这是简化的函数:
function launchRequest(requete,callback){
var db = openDatabase('database', '1.0', 'database', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql(requete,[],
function (tx, results) {
return callback(results.rows.length);
});
});
}
function nombreItems(num) {return num;}
我不知道如何获取函数的返回值。通常,我在函数末尾有一个 return(在标准 SQL 中),但在这里,结果被传输到另一个函数。
I am programming an application with Phonegap & Sencha Touch. I have my viewport.js file with Sencha interface and databasesFunctions.js with all databases and requests functions.
I want to call this line in viewport.js:
if(launchRequest('SELECT * from items',nombreItems)) alert('there are items');
Here is the simplified function:
function launchRequest(requete,callback){
var db = openDatabase('database', '1.0', 'database', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql(requete,[],
function (tx, results) {
return callback(results.rows.length);
});
});
}
function nombreItems(num) {return num;}
I don't know how to get the return value of my function. Usually, I have a return at the end of my function (in standard SQL), but here, the results are transmitted to another function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码将执行您所要求的操作,因为 WebSQL 接口是异步的,您无法“返回”值。
This code will do what you are asking, because the WebSQL interface is asynchronous you cant "return" values.