From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/idbkeyrange/lowerbound/index.html | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 files/zh-cn/web/api/idbkeyrange/lowerbound/index.html (limited to 'files/zh-cn/web/api/idbkeyrange/lowerbound/index.html') diff --git a/files/zh-cn/web/api/idbkeyrange/lowerbound/index.html b/files/zh-cn/web/api/idbkeyrange/lowerbound/index.html new file mode 100644 index 0000000000..8a9457d202 --- /dev/null +++ b/files/zh-cn/web/api/idbkeyrange/lowerbound/index.html @@ -0,0 +1,126 @@ +--- +title: IDBKeyRange.lowerBound() +slug: Web/API/IDBKeyRange/lowerBound +translation_of: Web/API/IDBKeyRange/lowerBound +--- +

{{ APIRef("IndexedDB") }}

+ +
+

{{domxref("IDBKeyRange")}} 接口的lowerBound()方法创建一个只有下限的新的键范围。默认情况下,它包含较低的端点值。

+
+ +

{{AvailableInWorkers}}

+ +

Syntax

+ +
var myIDBKeyRange = IDBKeyRange.lowerBound(lower);
+var myIDBKeyRange = IDBKeyRange.lowerBound(lower, open);
+
+ +

Parameters

+ +
+
lower 
+
指定新键范围的下限。
+
open {{optional_inline}}
+
指示下限是否排除端点值。默认值为false。
+
+ +

Return value

+ +

{{domxref("IDBKeyRange")}}: 新创建的键范围.

+ +

Exceptions

+ +

此方法可能引发以下类型的 {{domxref("DOMException")}} :

+ + + + + + + + + + + + + + +
ExceptionDescription
DataError +

The value parameter passed was not a valid key.

+ +
+
+ +

Example

+ +

下面的示例演示如何使用下限键范围。在这里,我们声明keyRangeValue = IDBKeyRange.lowerBound("F", false);— 一个包含值“F”及其后所有内容的范围。我们打开一个事务(使用 {{domxref("IDBTransaction")}})和一个对象存储,并使用 {{domxref("IDBObjectStore.openCursor")}}打开一个游标,声明keyRangeValue 为其可选的键范围值。这意味着光标将只检索键值为“F”及其后面的所有记录。如果使用IDBKeyRange.lowerBound("F", true);,则该范围将不包括端点“F”,仅包括其后面的值。

+ +
+

Note: 要获得一个更完整的示例,使您能够使用键范围进行实验,请查看我们的 IDBKeyRange-example实时查看该示例)。

+
+ +
function displayData() {
+  var keyRangeValue = IDBKeyRange.lowerBound("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.');
+      }
+    };
+  };
+ +
+ +

Specification

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('IndexedDB', '#widl-IDBKeyRange-lowerBound-IDBKeyRange-any-lower-boolean-open', 'lowerBound()')}}{{Spec2('IndexedDB')}}
{{SpecName("IndexedDB 2", "#dom-idbkeyrange-lowerbound-lower-open-lower", "lowerBound()")}}{{Spec2("IndexedDB 2")}}
+ +

Browser compatibility

+ +
+ + +

{{Compat("api.IDBKeyRange.lowerBound")}}

+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf