this.init = function (onupgradeneeded, onsuccess) {
var openRequest = indexedDB.open(dbName);
openRequest.onupgradeneeded = function (e) {
db = e.target.result;
if (!db.objectStoreNames.contains(objectStoreName)) {
console.log('Creating the ' + objectStoreName + ' objectstore');
db.createObjectStore(objectStoreName, { keyPath: "id", autoIncrement: true });
}
};
openRequest.onsuccess = function (e) {
db = e.target.result;
db.onerror = function (event) {
// Generic error handler for all errors targeted at this database requests
console.log("Database error: " + event.target.errorCode);
};
};
};
呼び出し元:
var idb = new Demo.IndexedDB();
idb.init();
init 関数が実行されると、最終的にopenRequest.onupgradeneeded
またはになりopenRequest.onsuccess
ます。
私が知りたいのは、両方の関数で呼び出される汎用コールバック関数を作成できるかどうかです。したがって、実行される2つの関数のどちらに関係なく、使用することでいつ完了したかを知ることができます
idb.init(function(){
//onupgradeneeded or onsuccess completed
});
アイデアが得られることを願っています。
ありがとう