Safari - 使用Facebook IndexedDB Polyfill的“TransactionInactiveError”

时间:2014-02-10 11:35:41

标签: javascript safari mobile-safari indexeddb polyfills

我们正在使用Facebook IndexedDB Polyfill来允许在Safari / Mobile Safari中使用IndexedDB API。但是,我们在尝试更新记录时遇到“TransactionInactiveError” - 错误源自Polyfill.js文件的第1567行:if (!me._active) throw new util.error("TransactionInactiveError");

这是我放在一起的一个简单例子。只需添加Facebook Polyfill脚本标记引用并在Safari中运行:

var db;
var request = indexedDB.open("polyfillTest");

request.onupgradeneeded = function () {
    // The database did not previously exist, so create object stores and indexes.
    db = request.result;
    var store = db.createObjectStore("books", {keyPath: "isbn"});
    var titleIndex = store.createIndex("by_title", "title", {unique: true});
    var authorIndex = store.createIndex("by_author", "author");

    // Populate with initial data.
    store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
    store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
    store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});

    updateItem(store);
};

request.onsuccess = function () {
    db = request.result;
};

function updateItem(store) {
    var request = store.get(123456);

    request.onsuccess = function () {
        var book = request.result;
        book.title = "New Title";
        book.author = "New Author";

        var updateRequest = store.put(book);
        updateRequest.onsuccess = function (evt) {
            console.log("Book updated successfully.");
        };
        updateRequest.onerror = function (evt) {
            console.error("Book could not be updated.");
        };
    };
}

任何帮助表示赞赏!

非常感谢

1 个答案:

答案 0 :(得分:1)

the last callback with a reference发布引用之前,事务通常保持活动状态。所以这告诉我你的交易是自动提交。

我怀疑这可能与您重复使用versionchangeputs的{​​{1}}交易有关。在经历了这个问题的许多令人头疼之后,我在library选择了我allow all version change transactions to fully commit之前的模型,然后尝试在同一商店进行CRUD操作。

我无法完全解释原因,但基于多年的挫折感,保持长期版本更改似乎是一个坏主意。