私は次の方法を持っています:
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;
}
}
問題は、次のようになることです。Uncaught TypeError:Object [objectWindow]にはメソッド'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);
}
ありがとう!