[英]IndexedDB - IDBObjectStore.get with IDBKeyRange - request only returns single object?
According to documentation :根据文档:
var request = objectStore.get(key);
Parameters参数
key钥匙
- The key or key range that identifies the record to be retrieved.标识要检索的记录的键或键范围。
So I expect that when I call get
with a key range, eg IDBKeyRange.bound(0, 4)
, I should somehow receive four values when the request succeeds?所以我希望当我使用键范围调用get
时,例如IDBKeyRange.bound(0, 4)
,当请求成功时我应该以某种方式接收四个值? But I only see a single value (tested in Chromium).但我只看到一个值(在 Chromium 中测试)。 Is this wrong documentation or wrong implementation, or am I missing a way to access all results without doing multiple requests?这是错误的文档还是错误的实现,还是我错过了一种无需多次请求即可访问所有结果的方法?
get(query)
The query parameter may be a key or an IDBKeyRange identifying the record to be retrieved.查询参数可以是标识要检索的记录的键或IDBKeyRange 。 If a range is specified, the method retrieves the first existing value in that range .如果指定了范围,则该方法检索该范围中的第一个现有值。
* Emphasis mine. * 强调我的。
To get all the values, use IDBObjectStore.getAll()
instead of .get()
or IDBObjectStore.openCursor()
:要获取所有值,请使用IDBObjectStore.getAll()
而不是.get()
或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 | -- IDBKeyRange - Web API |MDNMDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.