November 2011
Intermediate to advanced
384 pages
13h 23m
English
You can store an object into an IndexedDB object store using the add() request method generated by a read-write transaction. Because all transactions run asynchronously, the request/event model allows your code to know when a transaction has completed.
Only an array or generic object can be stored, and not simple strings or numbers. Custom objects that are built with constructors will be destroyed, but their properties and values will survive.
function addObject(object) { var transaction = db.transaction(objectStore, IDBTransaction. READ_WRITE); var store = transaction. objectStore(objectStore); var request = store.add(object); request.onsuccess = function(event) {...}; request.onerror = function(event) ...Read now
Unlock full access