任何人都可以帮助我如何从db中检索值?我的代码是
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
console.log("Run1");
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
});
db.transaction(function (tx){
for (var index = 1; index < 10; index++){
tx.executeSql('INSERT INTO LOGS (id,log) VALUES ('+index+', '+index+')');
}
});
}
</script>
此处创建表并插入10行。但我无法检索和显示值。
<input id="DBlist" type="submit" onClick='showList()' data-theme="b" value="Saved values" data-mini="false">
function showList()
{
var db = window.sqlitePlugin.openDatabase({name: "MYDB2"});
db.transaction(function(tx) {
tx.executeSql("select * from LOGS;", [], function(tx, res) {
// how can I display all the rows in console.log()
});
});
}
任何建议......
答案 0 :(得分:2)
查看文档
https://github.com/brodysoft/Cordova-SQLitePlugin
从中重写:
function(tx, res) {
for (var i = 0; i < res.rows.length; i++) {
console.log("Row = " + i + ", id = " + res.rows.item(i).id + ", log = " +
res.rows.item(i).log);
}
});