【发布时间】:2014-11-13 00:04:46
【问题描述】:
我想彻底检查一下是否有其他人在使用 Safari 7.1 和 IndexedDB 时遇到问题。似乎我收到了 UnknownError 类型的错误,根据 http://www.w3.org/TR/IndexedDB/ 的规范,当“操作因与数据库本身无关的原因而失败且未被任何其他错误涵盖”时发生。这发生在我第二次调用此函数时,在第一次调用调用回调(onSuccess 或 onError)之后。这是我创建对象存储的函数,它适用于 Chrome 和 Firefox。
IndexedDBClient.prototype.createObjectStore = function(options) {
if (this.checkIfObjectStoreExists(options.objectStoreName)) {
options.onError(this.objectStoreDNEMessage);
return;
}
var objectStore;
var objectStoreCreated = false;
var databaseOpened = false;
var version = this.database.version;
var dbName = this.database.name;
this.database.close();
var request = indexedDB.open(dbName, ++version);
var that = this;
request.onupgradeneeded = function(e) {
that.database = e.target.result;
objectStore = that.database.createObjectStore(options.objectStoreName, { keyPath: options.keyPathName });
objectStore.transaction.oncomplete = function(e) {
objectStoreCreated = true;
successCallback();
}
objectStore.transaction.onerror = function(e) {
options.onError(e);
};
};
request.onsuccess = function(e) {
databaseOpened = true;
successCallback();
}
request.onerror = function(e) {
options.onError(e);
};
request.onblocked = function(e) {
typeof options.onBlocked === 'function' && options.onBlocked();
};
function successCallback() {
// This is needed because we must be sure that both the objectstore creation transaction has completed,
// and the db open request has fired the onsuccess event.
objectStoreCreated && databaseOpened && options.onSuccess(objectStore);
}
};
【问题讨论】:
标签: javascript safari indexeddb