IDBRequest.result

Baseline Widely available

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

IDBRequest インターフェイスの読み取り専用プロパティ result は、要求の結果を返します。要求が完了していない場合、結果は参照できず、InvalidStateError 例外が投げられます。

メモ: この機能はウェブワーカー内で利用可能です。

任意

この例では、タイトルを指定してレコードを要求し、onsuccessIDBObjectStore から (objectStoreTitleRequest.result として参照できるようになった) 対応するレコードを取得し、レコードのプロパティ 1 個を更新し、更新したレコードをオブジェクトストアに書き戻します。動く例全体は、To-do Notifications を参照してください。(動く例を見る)

js
const title = "Walk dog";

// 通常通りトランザクションを開始します
const objectStore = db
  .transaction(["toDoList"], "readwrite")
  .objectStore("toDoList");

// この title をタイトルとして持つ TO-DO リストのオブジェクトを取得します
const objectStoreTitleRequest = objectStore.get(title);

objectStoreTitleRequest.onsuccess = () => {
  // result として返されたデータオブジェクトを取得します
  const data = objectStoreTitleRequest.result;

  // オブジェクトの notified の値を "yes" に更新します
  data.notified = "yes";

  // アイテムをデータベースに書き戻す別のリクエストを生成します
  const updateTitleRequest = objectStore.put(data);

  // 新しいリクエストが成功したら、また displayData() 関数を
  // 実行し、表示を更新します
  updateTitleRequest.onsuccess = () => {
    displayData();
  };
};

仕様書

Specification
Indexed Database API 3.0
# ref-for-dom-idbrequest-result①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
result

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報