aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/idbcursor/key
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/idbcursor/key
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/idbcursor/key')
-rw-r--r--files/zh-cn/web/api/idbcursor/key/index.html194
1 files changed, 194 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/idbcursor/key/index.html b/files/zh-cn/web/api/idbcursor/key/index.html
new file mode 100644
index 0000000000..573890a7fa
--- /dev/null
+++ b/files/zh-cn/web/api/idbcursor/key/index.html
@@ -0,0 +1,194 @@
+---
+title: IDBCursor.key
+slug: Web/API/IDBCursor/key
+translation_of: Web/API/IDBCursor/key
+---
+<p>{{APIRef("IndexedDB")}}</p>
+
+<div>
+<p><strong>key</strong>是只读属性,返回在游标中的位置。如果游标在范围之外,这个值会被置为undefined。游标的key可以是任何数据类型。</p>
+
+<p>{{AvailableInWorkers}}</p>
+</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox" style="font-size: 14px;">var <em>key = cursor</em>.key;</pre>
+
+<h3 id="值">值</h3>
+
+<p>任意类型</p>
+
+<h2 id="示例">示例</h2>
+
+<p>在该示例中,我们创建一个事务,检索一个存储对象,然后使用游标遍历所有存储在object store 中的记录。遍历的过程中,我们把类似(相簿标题,这是我们的键key),游标的key打印出来。</p>
+
+<p>我们可以不根据游标的key来选取数据;我们可以抓取所有。还要注意,在循环的每个迭代中,您可以使用cursor.value.foo从当前记录下获取数据。完整示例,请看<span style="line-height: 1.5;"><a href="https://github.com/mdn/IDBcursor-example/">IDBCursor example</a></span><span style="line-height: 1.5;"> (</span><a href="http://mdn.github.io/IDBcursor-example/" style="line-height: 1.5;">view example live</a><span style="line-height: 1.5;">.)</span></p>
+
+<pre style="font-size: 14px;"><span style="line-height: 1.5;">function displayData() {</span>
+ var transaction = db.transaction(['rushAlbumList'], "readonly");
+ var objectStore = transaction.objectStore('rushAlbumList');
+
+ objectStore.openCursor().onsuccess = function(event) {
+ var cursor = event.target.result;
+ if(cursor) {
+ var listItem = document.createElement('li');
+ listItem.innerHTML = cursor.value.albumTitle + ', ' + cursor.value.year;
+ list.appendChild(listItem);
+
+ console.log(cursor.key);
+ cursor.continue();
+ } else {
+ console.log('Entries all displayed.');
+ }
+ };
+};</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">说明</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('IndexedDB', '#widl-IDBCursor-key', 'key')}}</td>
+ <td>{{Spec2('IndexedDB')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName("IndexedDB 2", "#dom-idbcursor-key", "key")}}</td>
+ <td>{{Spec2("IndexedDB 2")}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</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>{{CompatVersionUnknown}}</td>
+ <td>10 {{property_prefix("moz")}}<br>
+ {{CompatGeckoDesktop("16.0")}}</td>
+ <td>10, partial</td>
+ <td>15</td>
+ <td>7.1</td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoDesktop("37.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Binary keys</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop("51.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Indexed Database 2.0</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatOpera(45)}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android Webview</th>
+ <th>Chrome for Android</th>
+ <th>Edge</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("22.0")}}</td>
+ <td>10</td>
+ <td>22</td>
+ <td>8</td>
+ </tr>
+ <tr>
+ <td>Available in workers</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("37.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Binary keys</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile("51.0")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Indexed Database 2.0</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatChrome(58)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatOperaMobile(45)}}</td>
+ <td>{{CompatUnknown}}</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>