根据文档,您可以创建一个数据库并使用以下内容填充它:
// PhoneGap is ready
//
function onDeviceReady() {
db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
//accessToken=new Table('Token','id unique, tokenType, tokenValue');
///createTable(accessToken);
}
// Populate the database
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 '+tname+' (id,data) VALUES (?, ?);',
[id,data],
function (transaction, resultSet) {
//success code
alert('sucessful insertion');
},
errorCB
);
}
// Transaction error callback
//
function errorCB(err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
但是,我可以在 db.transaction(populateDB, errorCB, successCB); 行中将参数传递给 populateDB 回调吗?? 如果是这样,我将如何访问该参数的值?请举个例子。任何帮助将不胜感激。