检查我的代码:
var db = openDatabase("Despesas", "1.0", "Despesas DB", 2000000);
db.transaction(createTbl, errorCB, successCB);
function errorCB(err){
alert('Error : ' + err.code);
}
function successCB(){
console.log('DB CREATED!');
db.transaction(queryDB, errorCB);
}
function createTbl(tx){
tx.executeSql('DROP TABLE IF EXISTS ENTRIES');
tx.executeSql('CREATE TABLE IF NOT EXISTS ENTRIES (id integer primary key autoincrement, entry TEXT NOT NULL)');
}
function callPopulate(){
db.transaction(
function populateDB(tx){
var userInput = document.getElementById('user').value;
tx.executeSql('INSERT INTO ENTRIES (entry) VALUES (?)', [userInput]);
//tx.executeSql('INSERT INTO ENTRIES (entry) VALUES ("'+ userInput + '")');
//alert('Input ok');
}, errorCB, successCB);
}
function queryDB(tx){
tx.executeSql('SELECT * FROM ENTRIES',[], querySuccess, errorCB);
}
function querySuccess(tx, results) {
document.getElementById('list').innerHTML = '';
var len = results.rows.length;
console.log("ENTRIES table: " + len + " rows found.");
for (var i=0; i<len; i++){
item = results.rows.item(i);
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
document.getElementById('list').innerHTML += '<li>' + item.data + '</li>';
console.log(item);
}
}
我登录item
到控制台,但它打印存储的对象。我试过console.log(item.data)
了,但它似乎没有给我预期的结果。我应该如何解决这个问题并返回真正的价值?我正在使用 Chrome。