Javascript、SQLite 数据库查询返回“Object Object”
我正在使用 Javascript 检查 sqlite 和 html5,这是我用来创建我的数据库、创建我的表并从我拥有的 3 个文本框中插入值的代码我遇到
function Add2DB()
{
var Tname = document.getElementById('txtName').value;
var Tprice = document.getElementById('txtPrice').value;
var Tqty = document.getElementById('txtQTY').value;
db.transaction(function (tx){
tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);
tx.executeSql('SELECT * FROM foo', [], function (tx, results){
var len = results.rows.length;
//For statements not allowed, just bring back first item in db
alert(results.rows.item(0).text)
});
});
}
的问题是,每当我迭代时这,它只是说Object对象
。我认为这是我遇到的 Javascript 问题,但我不确定
tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);
这一行也可能不正确,并且实际上可能没有正确插入映射值。有人可以解释一下吗?任何帮助或想法都会对我有很大帮助。谢谢。
I'm checking out the sqlite and html5 using Javascript, heres the code I'm using to create, my DB, create my table and insert values from 3 text boxes that I have
function Add2DB()
{
var Tname = document.getElementById('txtName').value;
var Tprice = document.getElementById('txtPrice').value;
var Tqty = document.getElementById('txtQTY').value;
db.transaction(function (tx){
tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);
tx.executeSql('SELECT * FROM foo', [], function (tx, results){
var len = results.rows.length;
//For statements not allowed, just bring back first item in db
alert(results.rows.item(0).text)
});
});
}
The problem I'm having is that whenever I iterate through this, It just says Object object
. I think it is a Javascript problem I'm having, I'm not certain though
tx.executeSql('INSERT INTO foo (name,price,qty) VALUES(?,?,?)',[Tname,Tprice,qty]);
This line might not be right either and may not be actually inserting the mapped values right. Can someone please shed some light on this. Any help, or ideas would help me greatly. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 console.log(需要带有 Firebug 的 Firefox 或基于 webkit 的浏览器),而不是警报,您可以轻松查看正在使用的内容的更多详细信息。
尝试 console.log("结果行:%o", results.rows.item(0).text);
如果它是一个物体,您将能够看到该物体并更好地理解它是什么。您需要查看这些浏览器中的 javascript 控制台。
Rather than an alert, if you use console.log (requiring Firefox with Firebug or a webkit-based browser) you can easily see more detail in what you're working with.
Try console.log("Results row: %o", results.rows.item(0).text);
If it is an object you'll be able to see into the object and better understand what it is. You'll need to look in the javascript console in those browsers.