getKey()
方法在
IDBObjectStore
interface returns an
IDBRequest
object, and, in a separate thread, returns the key selected by the specified query. This is for retrieving specific records from an object store.
If a key is successfully found, then a structured clone of it is created and set as the result of the request object.
注意: 此特征可用于 Web 工作者 .var request = objectStore.getKey(key);
The key or key range that identifies the record to be retrieved.
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. |
InvalidStateError
|
IDBObjectStore
has been deleted or removed.
|
let openRequest = indexedDB.open("telemetry");
openRequest.onsuccess = (event) => {
let db = event.target.result;
let store = db.transaction("netlogs").objectStore("netlogs");
let today = new Date();
let yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
let request = store.getKey(IDBKeyRange(yesterday, today));
request.onsuccess = (event) => {
let when = event.target.result;
alert("The 1st activity in last 24 hours was occurred at " + when);
};
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
索引数据库 API 草案
The definition of 'getKey()' in that specification. |
推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getKey
|
Chrome 48 | Edge ≤79 | Firefox 51 | IE ? | Opera 45 | Safari 10.1 | WebView Android 48 | Chrome Android 48 | Firefox Android 58 | Opera Android 43 | Safari iOS 10.3 | Samsung Internet Android 5.0 |
完整支持
兼容性未知
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