如何从SQLite SELECT返回结果
How to return a result from a SQLite SELECT?
我试图将结果从SQLite SELECT
传递到var res并显示它,但在警报中我得到"未定义"。如何正确退货?
function read(key){
app.db.transaction(function(tx) {
tx.executeSql('SELECT value FROM MyTable WHERE key = ?',
[key],
function(tx, results)
{
return results.rows.item(0)['value']
},
app.onError
);
return;
});
return;
}
res=read("pipi")
alert(res);
不能从异步函数返回值。您需要传递一个函数,该函数将与异步函数的结果一起执行,或者使用一个全局变量来保存结果。
res=read("pipi") // will always return undefined
可以声明全局变量和全局函数。
resultSelect = "";
function alertResultSelect(result){
alert(result);
}
然后在你的function(tx, results)
代码中添加
function(tx, results)
{
//Assign the results to the global variable.
resultSelect = results.rows.item(0)['value'];
// OR call the global function
alertResultSelect(results.rows.item(0)['value']);
}
相关文章:
- JSONP请求返回结果,但也触发error_callback
- async问题,JS Promise无法返回结果,但可以使用console.log
- Meteor js-控制台显示'未定义'即使返回结果
- 正在等待HTTP调用从函数返回结果
- 使用函数for循环遍历对象以更改值,然后返回结果
- 迭代 JSON 文件并且未在 Javascript 中正确返回结果
- Javascript 函数不返回结果
- 用逗号分隔返回结果中的对象
- 需要呈现MongoDB查询返回结果的特定索引/位置
- HTML5 文件阅读器如何返回结果
- javascript循环遍历列表项,并在数组中返回结果
- 使用jquery UI next按钮提交输入字段值,php将返回结果
- 在angularjs工厂中,如何在函数解析后返回结果
- 我在jQuery中的Rock Paper Scissors程序只在平局时返回结果
- 如何使用ajax调用php并返回结果
- 添加第二维度的Javascript未返回结果
- Node.js没有返回结果
- jquery裁剪图像selction未返回结果
- 如何在phonegap javascript函数中返回结果
- 如果文本筛选器在ng重复中未返回结果,则显示消息