aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/idbobjectstore/opencursor/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/idbobjectstore/opencursor/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/idbobjectstore/opencursor/index.html')
-rw-r--r--files/zh-cn/web/api/idbobjectstore/opencursor/index.html171
1 files changed, 171 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/idbobjectstore/opencursor/index.html b/files/zh-cn/web/api/idbobjectstore/opencursor/index.html
new file mode 100644
index 0000000000..764582ad9a
--- /dev/null
+++ b/files/zh-cn/web/api/idbobjectstore/opencursor/index.html
@@ -0,0 +1,171 @@
+---
+title: IDBObjectStore.openCursor
+slug: Web/API/IDBObjectStore/openCursor
+translation_of: Web/API/IDBObjectStore/openCursor
+---
+<p>{{ APIRef("IDBObjectStore") }}</p>
+
+<div>
+<p>{{domxref("IDBObjectStore")}} 的 <code>openCursor()</code> 方法 返回一个{{domxref("IDBRequest")}} 对象,并在一个单独的线程中,返回一个新的 {{domxref("IDBCursorWithValue")}} 对象。此方法目的是用一个游标来遍历一个对象存储空间。</p>
+</div>
+
+<p>若要确认此操作是否成功完成,请监听结果的 <code>success</code> 事件。</p>
+
+<p>{{AvailableInWorkers}}</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">var request = ObjectStore.openCursor(query, direction);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>query {{optional_inline}}</dt>
+ <dd>要查询的键或者 {{domxref("IDBKeyRange")}} 。如果传一个有效的键,则会默认为只包含此键的范围。如果此参数不传值,则默认为一个选择了该对象存储空间全部记录的键范围。</dd>
+ <dt>direction {{optional_inline}}</dt>
+ <dd>一个 {{domxref("IDBCursorDirection")}} 来告诉游标要移动的方向。有效的值有 <code>"next"</code> 、<code>"nextunique"</code> 、<code>"prev"</code> 和 <code>"prevunique"</code>。默认值是 <code>"next"</code>。</dd>
+</dl>
+
+<h3 id="返回">返回</h3>
+
+<p>一个 {{domxref("IDBRequest")}} 对象,在此对象上触发与此操作相关的后续事件。</p>
+
+<h3 id="异常">异常</h3>
+
+<p>此方法可能引起以下类型之一的 {{domxref("DOMException")}} :</p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">异常</th>
+ <th scope="col">描述</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>InvalidStateError</code></td>
+ <td>此 {{domxref("IDBObjectStore")}} 或{{domxref("IDBIndex")}} 已被删除。</td>
+ </tr>
+ <tr>
+ <td><code>TransactionInactiveError</code></td>
+ <td>此 {{domxref("IDBObjectStore")}} 的事务处于非活动状态。</td>
+ </tr>
+ <tr>
+ <td><code><span style="line-height: normal;">DataError</span></code></td>
+ <td>指定的键或键范围无效。</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="例子">例子</h2>
+
+<p>在下面这个简单的片段中,我们创建一个事务,检索一个对象存储空间,然后用一个游标去遍历该对象存储空间的所有记录:</p>
+
+<pre class="brush: js">var transaction = db.transaction("name", "readonly");
+var objectStore = transaction.objectStore("name");
+var request = objectStore.openCursor();
+request.onsuccess = function(event) {
+ var cursor = event.target.result;
+ if(cursor) {
+ // cursor.value 包含正在被遍历的当前记录
+ // 这里你可以对 result 做些什么
+ cursor.continue();
+ } else {
+ // 没有更多 results
+ }
+};
+
+</pre>
+
+<h2 id="规范">规范 </h2>
+
+<dl>
+</dl>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('IndexedDB', '#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction', 'openCursor()')}}</td>
+ <td>{{Spec2('IndexedDB')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName("IndexedDB 2", "#dom-idbobjectstore-opencursor", "openCursor()")}}</td>
+ <td>{{Spec2("IndexedDB 2")}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>23{{property_prefix("webkit")}}<br>
+ 24</td>
+ <td>10 {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16.0")}}</td>
+ <td>10, partial</td>
+ <td>15</td>
+ <td>7.1</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>4.4</td>
+ <td>{{CompatGeckoMobile("22.0")}}</td>
+ <td>1.0.1</td>
+ <td>10</td>
+ <td>22</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="另请参阅">另请参阅</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>