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);
					

参数

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.
推荐 初始定义

浏览器兼容性

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
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

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: