blob: 67e4d08b30fcbf2870364ebc14e10032e0e513c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
---
title: IDBDatabase.deleteObjectStore()
slug: Web/API/IDBDatabase/deleteObjectStore
translation_of: Web/API/IDBDatabase/deleteObjectStore
---
<p>{{ APIRef("IndexedDB") }}</p>
<div>
<p> <strong><code>deleteObjectStore()</code></strong> 方法从 {{domxref("IDBDatabase")}} 中销毁指定名称的对象存储,及这个对象存储所包含的任何索引。</p>
</div>
<p>与 {{ domxref("IDBDatabase.createObjectStore") }} 一样,<font><font>此方法</font></font><em><font><font>只能</font></font></em><font><font>在</font></font><a href="https://developer.mozilla.org/en-US/docs/IndexedDB/IDBTransaction#VERSION_CHANGE"><code>versionchange</code></a><font><font>事务中</font><font>调用</font><font>。</font></font></p>
<p>{{AvailableInWorkers}}</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>dbInstance</em>.deleteObjectStore(<em>name</em>);</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>name</code></dt>
<dd>将要删除的对象存储的名字</dd>
</dl>
<h3 id="异常">异常</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><code>InvalidStateError</code></td>
<td>Occurs if the method was not called from a <code>versionchange</code> transaction callback. For older WebKit browsers, you must call {{ APIRef("IDBVersionChangeRequest.setVersion")}} first.</td>
</tr>
<tr>
<td><code>TransactionInactiveError</code></td>
<td>Occurs if a request is made on a source database that doesn't exist (e.g. has been deleted or removed.) In Firefox previous to version 41, an <code>InvalidStateError</code> was raised in this case as well, which was misleading; this has now been fixed (see {{Bug("1176165")}}.)</td>
</tr>
<tr>
<td><code>NotFoundError</code></td>
<td>You are trying to delete an object store that does not exist. Names are case sensitive.</td>
</tr>
</tbody>
</table>
<h2 id="示例">示例</h2>
<pre class="brush: js">var dbName = "sampleDB";
var dbVersion = 2;
var request = indexedDB.open(dbName, dbVersion);
request.onupgradeneeded = function(e) {
var db = request.result;
if (e.oldVersion < 1) {
db.createObjectStore("store1");
}
if (e.oldVersion < 2) {
db.deleteObjectStore("store1");
db.createObjectStore("store2");
}
// etc. for version < 3, 4...
};</pre>
<h2 id="Specification"><span style="font-size: 2.14285714285714rem;">Specification</span></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-IDBDatabase-deleteObjectStore-void-DOMString-name', 'deleteObjectStore()')}}</td>
<td>{{Spec2('IndexedDB')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName("IndexedDB 2", "#dom-idbdatabase-deleteobjectstore", "deleteObjectStore()")}}</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.IDBDatabase.deleteObjectStore")}}</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>
|