javascript - sqlite ios电话间隙中的选择查询问题?
<p><p>谁能帮助我如何从数据库中检索值(value)?我的代码是</p>
<pre><code><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>
</code></pre>
<p>此处创建表并插入 10 行。但我无法检索和显示这些值。</p>
<pre><code> <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()
});
});
}
</code></pre>
<p>任何建议...</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>查看文档</p>
<pre><code>https://github.com/brodysoft/Cordova-SQLitePlugin
</code></pre>
<p>对其进行简短的重写:</p>
<pre><code>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);
}
});
</code></pre></p>
<p style="font-size: 20px;">关于javascript - sqlite ios电话间隙中的选择查询问题?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22694546/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22694546/
</a>
</p>
页:
[1]