IDBKeyRange:upperOpen 属性
注意:此功能在 Web Workers 中可用。
upperOpen
是
接口的一个只读属性,返回一个布尔值,指示上界值是否包含在键范围中。IDBKeyRange
值
一个布尔值。
值 | 指示 |
---|---|
true |
上界值不包含在键范围中。 |
false |
上界值包含在键范围中。 |
示例
以下示例说明了如何使用键范围。在此,我们声明 keyRangeValue = IDBKeyRange.upperBound("F", "W", true, true);
— 一个包含“F”和“W”之间所有内容但**不**包含它们本身的范围 — 因为上下界都被声明为开区间(true
)。我们打开一个事务(使用 IDBTransaction
)和一个对象存储,并使用 IDBObjectStore.openCursor
打开一个游标,将 keyRangeValue
声明为其可选的键范围值。
声明键范围后,我们将 upperOpen
属性值记录到控制台,其值应显示为“true”:上界是开放的,因此不包含在范围内。
注意:有关一个更完整的示例,允许您尝试键范围,请查看我们的 IDBKeyRange-example 仓库(也可以 在线查看示例)。
js
function displayData() {
const keyRangeValue = IDBKeyRange.bound("F", "W", true, true);
console.log(keyRangeValue.upperOpen);
const transaction = db.transaction(["fThings"], "readonly");
const objectStore = transaction.objectStore("fThings");
objectStore.openCursor(keyRangeValue).onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
const listItem = document.createElement("li");
listItem.textContent = `${cursor.value.fThing}, ${cursor.value.fRating}`;
list.appendChild(listItem);
cursor.continue();
} else {
console.log("Entries all displayed.");
}
};
}
规范
规范 |
---|
Indexed Database API 3.0 # ref-for-dom-idbkeyrange-upperopen① |
浏览器兼容性
加载中…
另见
- 使用 IndexedDB
- 开始事务:
IDBDatabase
- 使用事务:
IDBTransaction
- 设置键的范围:
IDBKeyRange
- 检索和修改数据:
IDBObjectStore
- 使用游标:
IDBCursor
- 参考示例:待办事项通知(查看实时示例)。