值
任意
异常
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 - 参考示例:待办事项通知(查看实时示例)。