November 2011
Intermediate to advanced
384 pages
13h 23m
English
You can retrieve objects out of an IndexedDB object store using a cursor. This is an enumeration tool that progresses through the list of all objects and returns them to your JavaScript program one by one:
function displayObjects() {
var transaction =
db.transaction(objectStore, IDBTransaction.
READ_ONLY);
var store = transaction.
objectStore(objectStore);
var request = store.openCursor();
request.onsuccess = function(event) {
if (cursor = event.target.result) {
renderObject(cursor.value);
cursor.continue();
}
};
}
The store.openCursor() method starts the object store retrieval process. For each object, a success event fires. You must retrieve the cursor from event.target. result, process the cursor’s ...
Read now
Unlock full access