1 回答

TA貢獻1811條經驗 獲得超5個贊
get(query)
查詢參數可以是標識要檢索的記錄的鍵或IDBKeyRange。如果指定了范圍,該方法將檢索該范圍中的第一個現有值。
--?IndexedDB API 2.0 - W3C
* 強調我的。
要獲取所有值,請使用orIDBObjectStore.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.');
? ? }
? };
}
添加回答
舉報