我正在使用PhoneGap Open Database API。根據這一文件數值應使用如下代碼PhoneGap存儲,將變量傳遞給db.transaction,SQL Lite
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
}
function successCB() {
alert("success!");
}
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
也能正常工作,但現在我想給一個變量傳遞給populateDB功能插入到現有的表。當我嘗試下面的代碼
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB("test variable"), errorCB, successCB);
「測試變量」字符串經過但tx未定義。有誰知道如何做到這一點?