简体   繁体   English

IndexedDB - 带有 IDBKeyRange 的 IDBObjectStore.get - 请求只返回单个对象?

[英]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 .如果指定了范围,则该方法检索该范围中的第一个现有值

-- IndexedDB API 2.0 - W3C -- IndexedDB API 2.0 - W3C

* 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.

相关问题 为什么对IDBObjectStore.get()的此调用导致混乱的行为? - Why is this call to IDBObjectStore.get() is resulting in confusing behavior? IDBKeyRange.only()仅返回第一个匹配记录 - IDBKeyRange.only() returns only first matching record 为什么我无法通过IndexedDB中的IDBKeyRange.bound函数获得正确的结果? - Why I cannot get the correct result through IDBKeyRange.bound function in IndexedDB? IndexedDB错误:未捕获的DataCloneError:无法在“ IDBObjectStore”上执行“ put”:无法克隆对象 - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned IndexedDB 错误:无法克隆 IDBObjectStore 符号 - IndexedDB error: IDBObjectStore Symbol could not be cloned 无法存储数据 IndexedDB(无法在“IDBObjectStore”上执行“添加”:评估 object 存储的键路径未产生值) - Cannot Store Data IndexedDB (Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value) 在一个查询中将IDBKeyRange.only和IDBKeyRange.lowerBound一起 - IDBKeyRange.only and IDBKeyRange.lowerBound together in one query IndexedDB:打开 `IDBObjectStore` 时出现 `DOMException`,事务已完成 - IndexedDB: `DOMException` while opening an `IDBObjectStore`, that the transaction has finished 在IndexedDB中,IDBObjectStore.put和IDBCursor.update有什么区别? - In IndexedDB, what is the difference between IDBObjectStore.put and IDBCursor.update? IndexedDB IDBObjectStore.add 错误:“无法将生成的键插入到值中” - IndexedDB IDBObjectStore.add error: "a generated key could not be inserted into the value"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM