這裏是我的代碼功能:WebStorage - 的ExecuteSQL給人不確定是不是在for循環
給定一個對象,我想在一個webStorage分貝插入一些數據。問題是,控制檯返回我一個「不確定是不是一個函數」,我不知道爲什麼
這裏是我的代碼
try {
db = openDatabase("mca", "1.0", "db mca", 200000);
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS planning_x_material(id INTEGER PRIMARY KEY AUTOINCREMENT, planning_id INTEGER, material_id INTEGER, material_name TEXT)", []);
}, onDbError, fillDb);
} catch(e) {
alert("webstorage error");
}
function callback_planning_material(obj) {
console.log(obj);
db.transaction(function(tx) {
for(var k = 0; k < obj.length; k++) {
for (var i = 0; i < obj[k].material.length; i++) {
(function (k, i) {
var planning = obj[k];
var material = planning.material[i];
tx.execuseSql("INSERT INTO planning_x_material(planning_id, material_id, material_name) VALUES (?, ?, ?)", [planning.id, material.id, material.name]); // here console gives me "undefined is not a function" error
})(k, i);
}
}
}, onDbError);
}
function fillDb() {
// example object
var obj = [
{
id: 1,
name: "name 1",
material: [
{ id: 1, name: "mat. 1" },
{ id: 2, name: "mat. 2" },
]
},
{
id: 2,
name: "name 2",
material: [
{ id: 3, name: "mat. 3" },
{ id: 4, name: "mat. 4" },
]
}
];
callback_planning_material(obj);
}
你'tx.ex ecuseSql',應該是'tx.executeSql'。 – RobH 2014-09-29 09:51:00