November 2011
Intermediate to advanced
384 pages
13h 23m
English
You can delete an object from an IndexedDB object store using the same basic code used to get() it by its key path; however, the get() example earlier in this chapter was a read-only task, and this is a read-write task:
function deleteObjectById(id) {
var transaction =
db.transaction(objectStore, IDBTransaction READ_WRITE); var store = transaction.
objectStore(objectStore);
var request = store.delete(id);
request.onsuccess = function(event) {
// Update the web page
};
request.onerror = function(event) {...};
}
Only the object with a key path value of id is deleted. The process to delete an object may not be instantaneous. Remember that the IndexedDB API runs asynchronously. Therefore, only after you ...
Read now
Unlock full access