值
任意
異常
InvalidStateErrorDOMException-
如果請求尚未完成,無法訪問結果,則嘗試訪問此屬性時會丟擲錯誤。
示例
以下示例請求一個給定的記錄標題,onsuccess 事件處理程式從 IDBObjectStore(透過 objectStoreTitleRequest.result 獲取)獲取關聯記錄,更新記錄的一個屬性,然後將更新後的記錄重新存入物件儲存。有關完整的可執行示例,請參閱我們的 待辦事項通知 應用(即時檢視示例)。
js
const title = "Walk dog";
// Open up a transaction as usual
const objectStore = db
.transaction(["toDoList"], "readwrite")
.objectStore("toDoList");
// Get the to-do list object that has this title as its title
const objectStoreTitleRequest = objectStore.get(title);
objectStoreTitleRequest.onsuccess = () => {
// Grab the data object returned as the result
const data = objectStoreTitleRequest.result;
// Update the notified value in the object to "yes"
data.notified = "yes";
// Create another request that inserts the item
// back into the database
const updateTitleRequest = objectStore.put(data);
// When this new request succeeds, run the displayData()
// function again to update the display
updateTitleRequest.onsuccess = () => {
displayData();
};
};
規範
| 規範 |
|---|
| Indexed Database API 3.0 # ref-for-dom-idbrequest-result① |
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。