计算 indexedDB 中对象存储中的记录在 Firefox 中不起作用

Counting the records in an object store in indexedDB not working in Firefox

我一直在从事基于 IndexedDB 的项目,我注意到 count() 方法在 Firefox 上无法正常工作。我不知道我是否遗漏了任何概念,因为我是新手,但我已经在 Chrome 和 Opera 上对其进行了测试,并且效果很好。

代码的简化版本是:

var database;
var openDB = indexedDB.open("newDB", 1);

openDB.onupgradeneeded = function () {
    database = openDB.result;
    var newStore = database.createObjectStore("example", { keyPath: "id", autoIncrement: true });
    newStore.createIndex("name", "name", { unique: false });
}
openDB.onsuccess = function () {
    database = openDB.result;
    var tx = database.transaction("example", "readwrite");
    var store = tx.objectStore("example");
    store.put({ name: "el_1" });
    store.put({ name: "el_2" });
    store.put({ name: "el_3" });
    store.put({ name: "el_4" });
    store.put({ name: "el_5" });        

    var transaction = database.transaction(['example'], 'readonly');
    var objectStore = transaction.objectStore('example');
    var counter = objectStore.index('name').count();
    counter.onsuccess = function () {
        total = counter.result;
        console.log(total);
    }
}

一切正常,除了 属性 方法 count() 的结果,即 returns 0,而不是 5。创建数据库,并将对象存储在 objectStore 中。

我发现了问题。当我在这里将代码重写为 post 时,我首先更改了一些内容以使其更易于理解。问题是我的代码曾经是:

   var createStore = database.createObjectStore("example", { keyPath: "id", autoIncrement: true });
    createStore.createIndex("id", "id", { unique: true});
    createStore.createIndex("name", "name", { unique: false });

然后:

    var counter = objectStore.index('id').count();

我想 Chrome 和 Opera 都可以,但 Firefox 不允许。 ^^