IndexedDB - IDBObjectStore.get with IDBKeyRange - 仅请求 returns 单个对象?

IndexedDB - IDBObjectStore.get with IDBKeyRange - request only returns single object?

根据documentation

var request = objectStore.get(key);

Parameters

key

  • The key or key range that identifies the record to be retrieved.

所以我希望当我用一个键范围调用 get 时,例如IDBKeyRange.bound(0, 4),当请求成功时,我应该以某种方式收到四个值?但我只看到一个值(在 Chromium 中测试)。这是错误的文档或错误的实施,还是我错过了一种无需执行多个请求即可访问所有结果的方法?

get(query)

The query parameter may be a key or an IDBKeyRange identifying the record to be retrieved. If a range is specified, the method retrieves the first existing value in that range.

-- IndexedDB API 2.0 - W3C

* 强调我的。

要获取所有值,请使用 IDBObjectStore.getAll() instead of .get() or IDBObjectStore.openCursor():

function displayData() {
  var keyRangeValue = IDBKeyRange.bound("A", "F");

  var transaction = db.transaction(['fThings'], 'readonly');
  var objectStore = transaction.objectStore('fThings');

  objectStore.openCursor(keyRangeValue).onsuccess = function(event) {
    var cursor = event.target.result;
    if(cursor) {
      var listItem = document.createElement('li');
      listItem.innerHTML = '<strong>' + cursor.value.fThing + '</strong>, ' + > cursor.value.fRating;
      list.appendChild(listItem);

      cursor.continue();
    } else {
      console.log('Entries all displayed.');
    }
  };
}

-- IDBKeyRange - Web APIs | MDN