getAll() 方法在 IDBObjectStore interface returns an IDBRequest object containing all objects in the object store matching the specified parameter or all objects in the store if no parameters are given.

If a value is successfully found, then a structured clone of it is created and set as the result of the request object.

This method produces the same result for:

  • a record that doesn't exist in the database
  • a record that has an undefined value

To tell these situations apart, you either call

  1. the openCursor() method with the same key. That method provides a cursor if the record exists, and no cursor if it does not.
  2. the count() method with the same key, which will return 1 if the row exists and 0 if it doesn't.

句法

var request = objectStore.getAll();
var request = objectStore.getAll(query);
var request = objectStore.getAll(query, count);
					

参数

query 可选
A key or IDBKeyRange to be queried. If nothing is passed, this will default to a key range that selects all the records in this object store.
count 可选
Specifies the number of values to return if more than one is found. 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 one of the following types:

异常 描述
TransactionInactiveError This IDBObjectStore 's transaction is inactive.
DataError The key or key range provided contains an invalid key or is null.
InvalidStateError IDBObjectStore has been deleted or removed.

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

规范

规范 状态 注释
索引数据库 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 ≤79 Firefox 44 IE ? Opera 35 Safari 10.1 WebView Android 48 Chrome Android 48 Firefox Android 48 Opera Android 35 Safari iOS 10.3 Samsung Internet Android 5.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: