diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/idbkeyrange/lowerbound/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/idbkeyrange/lowerbound/index.html')
-rw-r--r-- | files/zh-cn/web/api/idbkeyrange/lowerbound/index.html | 126 |
1 files changed, 126 insertions, 0 deletions
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 +--- +<p>{{ APIRef("IndexedDB") }}</p> + +<div> +<p>{{domxref("IDBKeyRange")}} 接口的<strong><code>lowerBound()</code></strong>方法创建一个只有下限的新的键范围。默认情况下,它包含较低的端点值。</p> +</div> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox" style="font-size: 14px;">var <em>myIDBKeyRange</em> = <em>IDBKeyRange</em>.lowerBound(<em>lower</em>); +var <em>myIDBKeyRange</em> = <em>IDBKeyRange</em>.lowerBound(<em>lower</em>, <em>open</em>); +</pre> + +<h3 id="Parameters">Parameters</h3> + +<dl> + <dt>lower </dt> + <dd>指定新键范围的下限。</dd> + <dt>open<em> </em>{{optional_inline}}</dt> + <dd>指示下限是否排除端点值。默认值为false。</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>{{domxref("IDBKeyRange")}}: 新创建的键范围.</p> + +<h3 id="Exceptions">Exceptions</h3> + +<p>此方法可能引发以下类型的 {{domxref("DOMException")}} :</p> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Exception</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td><font face="Courier New, Andale Mono, monospace"><span style="line-height: normal;">DataError</span></font></td> + <td> + <p>The value parameter passed was not a valid key.</p> + + <div></div> + </td> + </tr> + </tbody> +</table> + +<h2 id="Example">Example</h2> + +<p>下面的示例演示如何使用下限键范围。在这里,我们声明<code>keyRangeValue = IDBKeyRange.lowerBound("F", false);</code>— 一个包含值“F”及其后所有内容的范围。我们打开一个事务(使用 {{domxref("IDBTransaction")}})和一个对象存储,并使用 {{domxref("IDBObjectStore.openCursor")}}打开一个游标,声明<code>keyRangeValue</code> 为其可选的键范围值。这意味着光标将只检索键值为“F”及其后面的所有记录。如果使用<code>IDBKeyRange.lowerBound("F", true);</code>,则该范围将不包括端点“F”,仅包括其后面的值。</p> + +<div class="note"> +<p><strong>Note</strong>: 要获得一个更完整的示例,使您能够使用键范围进行实验,请查看我们的 <a href="https://github.com/mdn/indexeddb-examples/tree/master/idbkeyrange">IDBKeyRange-example</a>(<a href="https://mdn.github.io/indexeddb-examples/idbkeyrange/">实时查看该示例</a>)。</p> +</div> + +<pre class="brush: js" style="font-size: 14px;">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.'); + } + }; + };</pre> + +<div></div> + +<h2 id="Specification">Specification</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('IndexedDB', '#widl-IDBKeyRange-lowerBound-IDBKeyRange-any-lower-boolean-open', 'lowerBound()')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#dom-idbkeyrange-lowerbound-lower-open-lower", "lowerBound()")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.IDBKeyRange.lowerBound")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li> + <li>Starting transactions: {{domxref("IDBDatabase")}}</li> + <li>Using transactions: {{domxref("IDBTransaction")}}</li> + <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li> + <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li> + <li>Using cursors: {{domxref("IDBCursor")}}</li> + <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</li> +</ul> |