IDBIndex.openKeyCursor()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers.

Phương thức openKeyCursor() của giao diện IDBIndex trả về một đối tượng IDBRequest và, trong một luồng riêng biệt, tạo một cursor trên phạm vi khóa đã chỉ định, được sắp xếp theo index này.

Cú pháp

js
openKeyCursor()
openKeyCursor(query)
openKeyCursor(query, direction)

Tham số

query Optional

Khóa hoặc phạm vi khóa để so khớp.

direction Optional

Hướng di chuyển của cursor.

Giá trị trả về

Một đối tượng IDBRequest.

Ngoại lệ

TransactionInactiveError DOMException

Transaction của đối tượng này đang không hoạt động.

DataError DOMException

Khóa hoặc phạm vi khóa không hợp lệ.

Ví dụ

js
const request = myIndex.openKeyCursor();
request.onsuccess = () => {
  console.log(request.result);
};

Thông số kỹ thuật

Specification
Indexed Database API 3.0
# ref-for-dom-idbindex-openkeycursor①

Tương thích trình duyệt