count()
方法在
IDBObjectStore
interface returns an
IDBRequest
object, and, in a separate thread, returns the total number of records that match the provided key or
IDBKeyRange
. If no arguments are provided, it returns the total number of records in the store.
varrequest= ObjectStore.count(); varrequest= ObjectStore.count(query);
IDBKeyRange
object that specifies a range of records you want to count.
IDBRequest
object on which subsequent events related to this operation are fired.
此方法可能引发
DOMException
of one of the following types:
| 异常 | 描述 |
|---|---|
InvalidStateError
|
This
IDBObjectStore
has been deleted.
|
TransactionInactiveError
|
This
IDBObjectStore
's transaction is inactive.
|
DataError
|
The specified key or key range is invalid. |
In this simple fragment we create a transaction, retrieve an object store, then count the number of records in the store using
count()
— when the success handler fires, we log the count value (an integer) to the console.
var transaction = db.transaction(['fThings'], 'readonly');
var objectStore = transaction.objectStore('fThings');
var countRequest = objectStore.count();
countRequest.onsuccess = function() {
console.log(countRequest.result);
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
索引数据库 API 2.0
The definition of 'count()' in that specification. |
推荐 | |
|
索引数据库 API 草案
The definition of 'count()' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
count
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 |
WebView Android
Yes
|
Chrome Android
25
|
Firefox Android 22 | Opera Android 14 | Safari iOS 8 |
Samsung Internet Android
1.5
|
完整支持
部分支持
要求使用供应商前缀或不同名称。
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
IDBObjectStore
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactory
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest