| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/API/IDBTransaction/objectStore | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
Diese Funktion ist gut etabliert und funktioniert auf vielen Gerten und in vielen Browserversionen. Sie ist seit Juli 2015 browserbergreifend verfgbar.
Hinweis: Diese Funktion ist in Web Workers verfgbar.
Die objectStore()-Methode des
IDBTransaction-Interfaces gibt einen Object Store zurck, der bereits zum Scope dieser Transaktion hinzugefgt wurde.
Jeder Aufruf dieser Methode am gleichen Transaktionsobjekt mit dem gleichen Namen gibt
die gleiche IDBObjectStore-Instanz zurck. Wird diese Methode an einem anderen
Transaktionsobjekt aufgerufen, wird eine andere IDBObjectStore-Instanz zurckgegeben.
objectStore(name)
nameDer Name des angeforderten Object Stores.
Ein IDBObjectStore-Objekt zum Zugriff auf einen Object Store.
NotFoundError DOMExceptionWird ausgelst, wenn der angeforderte Object Store nicht im Scope dieser Transaktion ist.
InvalidStateError DOMExceptionWird ausgelst, wenn die Anforderung an einem Quellobjekt gemacht wurde, das gelscht oder entfernt wurde, oder wenn die Transaktion abgeschlossen ist.
Im folgenden Codebeispiel ffnen wir eine Lese-/Schreib-Transaktion in unserer Datenbank und fgen einige Daten in einen Object Store ein. Beachten Sie auch die Funktionen, die den Transaktionsereignis-Handlern beigefgt sind, um ber das Ergebnis des Transaktionsstarts im Falle eines Erfolgs oder Fehlschlags zu berichten. Fr ein vollstndiges funktionierendes Beispiel siehe unsere To-do Notifications-App (Beispiel live ansehen).
const note = document.getElementById("notifications");
// an instance of a db object for us to store the IDB data in
let db;
// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);
DBOpenRequest.onsuccess = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Database initialized.";
// store the result of opening the database in the db variable.
// This is used a lot below
db = DBOpenRequest.result;
// Run the addData() function to add the data to the database
addData();
};
function addData() {
// Create a new object ready for being inserted into the IDB
const newItem = [
{
taskTitle: "Walk dog",
hours: 19,
minutes: 30,
day: 24,
month: "December",
year: 2013,
notified: "no",
},
];
// open a read/write db transaction, ready for adding the data
const transaction = db.transaction(["toDoList"], "readwrite");
// report on the success of opening the transaction
transaction.oncomplete = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Transaction completed: database modification finished.";
};
transaction.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Transaction not opened due to error. Duplicate items not allowed.";
};
// create an object store on the transaction
const objectStore = transaction.objectStore("toDoList");
// add our newItem object to the object store
const objectStoreRequest = objectStore.add(newItem[0]);
objectStoreRequest.onsuccess = (event) => {
// report the success of the request (this does not mean the item
// has been stored successfully in the DB - for that you need transaction.onsuccess)
note.appendChild(document.createElement("li")).textContent =
"Request successful.";
};
}
| Spezifikation |
|---|
| Indexed Database API 3.0 # ref-for-dom-idbtransaction-objectstore |
IDBDatabaseIDBTransactionIDBKeyRangeIDBObjectStoreIDBCursorIDBTransactionDer Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |