getAll() 方法在 IDBIndex interface retrieves all objects that are inside the index.

There is a performance cost associated with looking at the value property of a cursor, because the object is created lazily. To use a feature like getAll() , the browser has to create all the objects at once. If you are just interested in looking at each of the keys, for instance, it is more efficient to use a cursor . If you are trying to get an array of all the objects in an object store, though, you should use getAll() .

句法

var getAllKeysRequest = IDBIndex.getAll();
var getAllKeysRequest = IDBIndex.getAll(query);
var getAllKeysRequest = IDBIndex.getAll(query, count);
					

参数

query 可选
A key or an IDBKeyRange identifying the records to retrieve. If this value is null or missing, the browser will use an unbound key range.
count 可选
The number records to return. If this value exceeds the number of records in the query, the browser will only retrieve the first item. If it is lower than 0 or greater than 2 32 -1 a TypeError exception will be thrown.

返回值

IDBRequest object on which subsequent events related to this operation are fired.

异常

此方法可能引发 DOMException of the following types:

异常 描述
TransactionInactiveError This IDBIndex 's transaction is inactive.
InvalidStateError IDBIndex has been deleted or removed.

A TypeError exception is thrown if the count parameter is not between 0 and 2 32 -1 included.

范例

var myIndex = objectStore.index('index');
var getAllRequest = myIndex.getAll();
getAllRequest.onsuccess = function() {
  console.log(getAllRequest.result);
}
					

规范

规范 状态 注释
索引数据库 API 草案
The definition of 'getAll()' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getAll Chrome 48 Edge ≤18 Firefox 44 IE No Opera 35 Safari 10.1 WebView Android 48 Chrome Android 48 Firefox Android 44 Opera Android 35 Safari iOS 10.3 Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: