IDBRequest: result-Eigenschaft

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.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die schreibgeschützte Eigenschaft result des IDBRequest-Interfaces gibt das Ergebnis der Anfrage zurück.

Wert

any

Ausnahmen

InvalidStateError DOMException

Wird ausgelöst, wenn versucht wird, auf die Eigenschaft zuzugreifen, obwohl die Anfrage noch nicht abgeschlossen ist und daher das Ergebnis nicht verfügbar ist.

Beispiele

Das folgende Beispiel fragt einen bestimmten Titel an. Bei onsuccess wird der zugehörige Datensatz aus dem IDBObjectStore abgerufen (verfügbar als objectStoreTitleRequest.result), eine Eigenschaft des Datensatzes wird aktualisiert und der aktualisierte Datensatz wird dann zurück in den Objektstore gelegt. Für ein vollständiges funktionierendes Beispiel siehe unsere To-do Notifications App (Beispiel live ansehen).

js
const title = "Walk dog";

// Open up a transaction as usual
const objectStore = db
  .transaction(["toDoList"], "readwrite")
  .objectStore("toDoList");

// Get the to-do list object that has this title as its title
const objectStoreTitleRequest = objectStore.get(title);

objectStoreTitleRequest.onsuccess = () => {
  // Grab the data object returned as the result
  const data = objectStoreTitleRequest.result;

  // Update the notified value in the object to "yes"
  data.notified = "yes";

  // Create another request that inserts the item
  // back into the database
  const updateTitleRequest = objectStore.put(data);

  // When this new request succeeds, run the displayData()
  // function again to update the display
  updateTitleRequest.onsuccess = () => {
    displayData();
  };
};

Spezifikationen

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

Browser-Kompatibilität

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

Siehe auch