【问题标题】:IndexedDb get all occurrences in indexIndexedDb 获取索引中的所有出现
【发布时间】:2015-03-31 14:50:21
【问题描述】:

在 IndexedDb 中,我有一个这样的索引:

store.createIndex('distinctEqual', 'distinctEqualString', {unique: false});

当我这样做时:

var tx = db.transaction(dbSettings.objectStore, "readwrite");
var store = tx.objectStore(dbSettings.objectStore);
var index = store.index('distinctEqual');
var reqIndex = index.get("pippo");

是否可以在不使用该 IndexedDb 索引中的光标的情况下获取所有出现的“pippo”?

编辑

如果我这样做:

var cursorIndex =       
index.openKeyCursor(IDBKeyRange.only(currItem.distinctEqualString));
cursorIndex.onsuccess = function(evt) {
    //Can I know how many elements are there in cursorIndex?
};

在评论中,我能知道 cursorIndex 中有多少个元素吗?

【问题讨论】:

    标签: javascript jquery google-chrome indexeddb


    【解决方案1】:

    您将需要使用光标。这就是使用游标的原因。

    【讨论】:

      【解决方案2】:

      get 只会返回满足 keyrange 的第一个项目。如果要检索所有内容,可以使用您提到的光标。如果您想知道项目的数量,您可以使用count 方法。

      【讨论】:

      • 光标无法使用count方法。
      • 你可以通过在光标上循环时保持索引来计算项目的数量,但是如果你只需要知道项目的数量,最好使用count方法
      猜你喜欢
      • 2014-05-12
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      相关资源
      最近更新 更多