From 65cc6eabd71b1bceccf6fd3d3d4970c2955f3784 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 10 Dec 2020 08:37:18 -0500 Subject: dump 2020-12-10 --- files/zh-cn/web/api/idbkeyrange/index.html | 40 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'files/zh-cn/web/api/idbkeyrange/index.html') diff --git a/files/zh-cn/web/api/idbkeyrange/index.html b/files/zh-cn/web/api/idbkeyrange/index.html index 32481c3a02..af65cfbb11 100644 --- a/files/zh-cn/web/api/idbkeyrange/index.html +++ b/files/zh-cn/web/api/idbkeyrange/index.html @@ -16,10 +16,10 @@ translation_of: Web/API/IDBKeyRange

{{APIRef("IndexedDB")}}

-

The IDBKeyRange interface of the IndexedDB API represents a continuous interval over some data type that is used for keys. Records can be retrieved from {{domxref("IDBObjectStore")}} and {{domxref("IDBIndex")}} objects using keys or a range of keys. You can limit the range using lower and upper bounds. For example, you can iterate over all values of a key in the value range A–Z.

+

IndexedDB API 的IDBKeyRange接口表示一些数据类型上的键的连续间隔。可以使用一个键或某个范围的键从{{domxref("IDBObjectStore")}} 和{{domxref("IDBIndex")}} 对象中检索记录。您也可以指定键的上界和下界来限制范围。例如,您可以遍历值范围a - z中的键的所有值。

-

A key range can be a single value or a range with upper and lower bounds or endpoints. If the key range has both upper and lower bounds, then it is bounded; if it has no bounds, it is unbounded. A bounded key range can either be open (the endpoints are excluded) or closed (the endpoints are included). To retrieve all keys within a certain range, you can use the following code constructs:

+

键范围可以是单个值,也可以是具有上界、下界或端点的范围。如果键范围同时有上界或下界,那么它是有界的,否则是无界的。有界键范围可以是开放的(不包含端点)或闭合的(包含了端点)。要检索一定范围内的所有键值,可以使用以下的代码结构:

@@ -66,21 +66,21 @@ translation_of: Web/API/IDBKeyRange
-

A key is in a key range if the following conditions are true:

+

如果以下条件为true,则键包含在键范围中:

@@ -91,13 +91,13 @@ translation_of: Web/API/IDBKeyRange
{{domxref("IDBKeyRange.lower")}} {{readonlyInline}}
-
Lower bound of the key range.
+
键范围的下界
{{domxref("IDBKeyRange.upper")}} {{readonlyInline}}
-
Upper bound of the key range.
+
键范围的上界
{{domxref("IDBKeyRange.lowerOpen")}} {{readonlyInline}}
-
Returns false if the lower-bound value is included in the key range.
+
如果下界值包含在键范围内,则返回false。
{{domxref("IDBKeyRange.upperOpen")}} {{readonlyInline}}
-
Returns false if the upper-bound value is included in the key range.
+
如果上界值包含在键范围内,则返回false。

Methods

@@ -106,31 +106,31 @@ translation_of: Web/API/IDBKeyRange
{{domxref("IDBKeyRange.bound()")}}
-
Creates a new key range with upper and lower bounds.
+
指定上界和下界来创建一个新的键范围
{{domxref("IDBKeyRange.only()")}}
-
Creates a new key range containing a single value.
+
指定单个键值来创建一个新的键范围
{{domxref("IDBKeyRange.lowerBound()")}}
-
Creates a new key range with only a lower bound.
+
指定结果集的下界来创建一个新的键范围
{{domxref("IDBKeyRange.upperBound()")}}
-
Creates a new upper-bound key range.
+
指定结果集的上界来创建一个新的键范围

Instance methods

{{domxref("IDBKeyRange.includes()")}}
-
Returns a boolean indicating whether a specified key is inside the key range.
+
返回一个布尔值来表示指定的键是否在键范围内。

Examples

-

The following example illustrates how you'd use a key range. Here we declare a keyRangeValue as a range between values of "A" and "F". We open a transaction (using {{domxref("IDBTransaction")}}) and an object store, and open a Cursor with {{domxref("IDBObjectStore.openCursor")}}, declaring keyRangeValue as its optional key range value. This means that the cursor will only retrieve records with keys inside that range. This range includes the values "A" and "F", as we haven't declared that they should be open  bounds. If we used IDBKeyRange.bound("A", "F", true, true);, then the range would not include "A" and "F", only the values between them.

+

以下示例用以说明该如果使用键范围。在此我们将 keyRangeValue 声明为A~F之间的范围。我们打开一个事务 (使用 {{domxref("IDBTransaction")}}) 和一个对象存储, 并用 {{domxref("IDBObjectStore.openCursor")}}打开一个游标,其中keyRangeValue是一个可选的键范围值,指定之后游标将只检索键在该范围内的记录。这里的键范围包括了“A”和“F”,因为我们还没声明键范围为开放边界。如果我们使用 IDBKeyRange.bound("A", "F", true, true);,那么这个键范围将不包括“A”和“F”,只包含它们之间的值。

Note: For a more complete example allowing you to experiment with key range, have a look at our IDBKeyRange-example repo (view the example live too.)

-
function displayData() {
+
function displayData() {
   var keyRangeValue = IDBKeyRange.bound("A", "F");
 
   var transaction = db.transaction(['fThings'], 'readonly');
-- 
cgit v1.2.3-54-g00ecf