我想进行健全性检查,看看是否有其他人在使用 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);
}
};
最佳答案
Safari 浏览器中的 IndexedDB API 有 bug多个商店交易。
关于javascript - 使用 IndexedDB 创建多个对象存储时,Safari 7.1 中出现 UnknownError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26899035/