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/idbobjectstore/indexnames | |
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/idbobjectstore/indexnames')
-rw-r--r-- | files/zh-cn/web/api/idbobjectstore/indexnames/index.html | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/idbobjectstore/indexnames/index.html b/files/zh-cn/web/api/idbobjectstore/indexnames/index.html new file mode 100644 index 0000000000..c124f70a9b --- /dev/null +++ b/files/zh-cn/web/api/idbobjectstore/indexnames/index.html @@ -0,0 +1,110 @@ +--- +title: IDBObjectStore.indexNames +slug: Web/API/IDBObjectStore/indexNames +translation_of: Web/API/IDBObjectStore/indexNames +--- +<p>{{ APIRef("IndexedDB") }}</p> + +<div> +<p>{{domxref("IDBObjectStore")}} 的只读属性 <strong><code>indexNames</code></strong> 返回此对象存储中对象的 <a href="https://developer.mozilla.org/en/IndexedDB#gloss_index" title="en/IndexedDB#gloss index">indexes</a> 名称(name)列表。</p> + +<p>{{AvailableInWorkers}}</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">var <em>myindexNames</em> = <em>objectStore</em>.indexNames;</pre> + +<h3 id="Value">Value</h3> + +<p>一个 {{domxref("DOMStringList")}}.</p> + +<h2 id="Example">Example</h2> + +<p>在下面的代码片段中,我们在数据库上打开一个读/写事务并使用 <code>add()</code> 向对象存储添加一些数据。创建对象存储后,我们将打印 <span style="background-color: #fafbfc; font-family: consolas,monaco,andale mono,monospace; font-size: 1rem; line-height: 19px; white-space: pre;"><code>objectStore.indexNames</code></span> 到控制台。有关完整的工作示例,请参阅我们的 <a href="https://github.com/mdn/to-do-notifications/">待办事项通知</a>应用程序<span style="line-height: 1.5;"> ( </span><a href="http://mdn.github.io/to-do-notifications/">实时查看示例</a><span style="line-height: 1.5;"> )</span></p> + +<pre class="brush: js" style="font-size: 14px;">// 让我们来打开我们的数据库 +<span style="line-height: 1.5;">var DBOpenRequest = window.indexedDB.open("toDoList", 4); + +</span><span style="line-height: 1.5;">DBOpenRequest.onsuccess = function(event) {</span> + note.innerHTML += '<li>Database initialised.</li>'; + + // 将打开数据库的结果存储在db变量中 + // 下面经常用到这个 + db = this.result; + + // 运行 addData() 函数将数据添加到数据库 + addData(); +}; + +function addData() { + // 创建一个新对象以准备插入到IDB中 + var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ]; + + // 打开读/写数据库事务,准备添加数据 + var transaction = db.transaction(["toDoList"], "readwrite"); + + // 当所有事情都完成时,报告事务完成的成功情况 + transaction.oncomplete = function(event) { + note.innerHTML += '<li>Transaction completed.</li>'; + }; + + + transaction.onerror = function(event) { + note.innerHTML += '<li>Transaction not opened due to error. Duplicate items not allowed.</li>'; + }; + + // 在事务上创建对象存储 + var objectStore = transaction.objectStore("toDoList"); + console.log(objectStore.indexNames); + + // 请求将 newItem 对象 添加到对象存储区 + var objectStoreRequest = objectStore.add(newItem[0]); + + objectStoreRequest.onsuccess = function(event) { + // 报告我们请求的成功 + note.innerHTML += '<li>Request successful.</li>'; + }; +};</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', '#dom-idbobjectstore-indexnames', 'indexNames')}}</td> + <td>{{Spec2('IndexedDB')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("IndexedDB 2", "#dom-idbobjectstore-indexnames", "indexNames")}}</td> + <td>{{Spec2("IndexedDB 2")}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.IDBObjectStore.indexNames")}}</p> +</div> + +<h2 id="查看其它内容">查看其它内容</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">使用 IndexedDB</a></li> + <li><span id="w_40">启动</span><span id="w_41">事务</span> : {{domxref("IDBDatabase")}}</li> + <li>使用事务 : {{domxref("IDBTransaction")}}</li> + <li>设置键的范围 : {{domxref("IDBKeyRange")}}</li> + <li>检索和更改数据 : {{domxref("IDBObjectStore")}}</li> + <li>使用游标 : {{domxref("IDBCursor")}}</li> + <li>参考示例 : <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> |