面向對象的,我有以下方法:的PhoneGap的localStorage和JS
DBConnection.prototype.successHandler = function(){
console.log("DB_INFO: Schema created");
for (k in this) console.log(k);
this.setStatus(DB_STATUS_OK);
}
我把這種在交易這樣的:
DBConnection.prototype.createSchema = function(){
try {
this.c2db.transaction(
function(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS person(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL DEFAULT "");',
[], this.nullDataHandler, this.errorHandler);
tx.executeSql("INSERT INTO person(id, name) VALUES (NULL, 'miloud');",
[], this.nullDataHandler, this.errorHandler);
},
this.errorHandler,
this.successHandler
);
} catch(e){
console.log("DB_ERROR: error during insert with message: " + e);
return;
}
}
的問題是,我得到:遺漏的類型錯誤:對象[對象窗口]沒有方法'setStatus'這清楚地表明我正在訪問的不是我在成功回調中使用的DBConnection
實例。怎麼來的?這個回調裏面指的是什麼?有沒有辦法解決這個問題?
編輯
回調定義爲:
DBConnection.prototype.errorHandler = function(errorMsg){
console.log("DB_ERROR: error creating schema with msg " + errorMsg.message);
}
DBConnection.prototype.successHandler = function(){
console.log("DB_INFO: Schema created");
for (k in this) console.log(k);
this.setStatus(DB_STATUS_OK);
}
而且setStatus方法
DBConnection.prototype.setStatus = function(str_status){
localStorage.setItem(db_name, str_status);
}
謝謝!
一句話,謝謝! – CoolStraw 2012-07-14 10:54:46