我有一个使用indexeddb的应用程序。 我正在开发Windows并正在使用Chrome进行测试。在Chrome中一切正常。但是当我在Mac Book上使用Safari进行测试时,它失败了。
Safari(版本7.1.3)失败的部分代码,但不是Chrome:
var request = indexedDB.open("db", 1);
request.onsuccess = function() {
var db = this.result;
var tx = db.transaction ("store", "readonly");
var store = tx.objectStore("store");
var item = store.get(localId); //it is provided;
item.onsuccess= function () {
var data = item.result; // the result is underfined, as well as data
console.log("Krippe is: " + data.krippe); //fails here;
if (data){
console.log("IInstitution.krippe = " + data.krippe);
DisplayValue = data.krippe;
}
initPage();
};
item.onerror = function () {
console.log("Error: " + item.result.errorCode);
}
}
我在Safari中使用了调试器,而
item.onsuccess()
实际上被触发了,它进入了函数。但是
item.result
仅在Safari中未定义。在Chrome中它完美无缺。
任何想法我做错了什么?以及如何解决它?
最佳
答案 0 :(得分:0)
我没有Mac可以测试,但我会猜测它是Safari中的另一个IndexedDB错误。许多人都有报道。
这个可能已经在雷达下滑落,因为没有多少人使用这样的API。我使用IndexedDB多年而不知道在this之前将结果放回请求对象。相反,大多数人都会访问这样的请求结果:
item.onsuccess= function (event) {
var data = event.target.result;
这可能适用于Safari,但要注意Safari中还有大量其他的IndexedDB错误。