IDBRequest:readyState 属性
注意:此功能在 Web Workers 中可用。
IDBRequest 接口的只读属性 readyState 返回请求的状态。
每个请求都始于 pending 状态。当请求成功完成或发生错误时,状态会变为 done。
值
以下字符串之一
示例
以下示例请求一个给定的记录标题,onsuccess 从 IDBObjectStore 中获取相关记录(可通过 objectStoreTitleRequest.result 访问),更新记录的一个属性,然后将更新后的记录放入另一个请求中的对象存储中。第二个请求的 readyState 将被记录到开发者控制台中。有关完整的可运行示例,请参阅我们的 To-do Notifications 应用(在线查看示例)。
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);
// Log the readyState of this request
console.log(
`The readyState of this request is ${updateTitleRequest.readyState}`,
);
// 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-readystate① |
浏览器兼容性
加载中…
另见
- 使用 IndexedDB
- 开始事务:
IDBDatabase - 使用事务:
IDBTransaction - 设置键的范围:
IDBKeyRange - 检索和修改数据:
IDBObjectStore - 使用游标:
IDBCursor - 参考示例:待办事项通知(查看实时示例)。