HTML and CSS Reference
In-Depth Information
In order to define the database transaction for updating an object store, the application
would call the IndexedDB method transaction to define the type and scope of the
transaction. Because updating a database requires writing to the object store, the type is
specified as 'readwrite' . The second parameter, the scope of the transaction, specifies
the various object stores the application will be writing to.
With the transaction defined, the application can now get the object store it needs to update.
Calling the transaction's method, objectStore , with a parameter specifying the name
of the object store will return the object store. At this point, the application can update the
object store by invoking its put method, with the changed data object as its parameter.
Deleting task items follows a similar procedure. But once the application has the object
store, it will invoke the object store's delete method, with the data object's key as a
parameter. Delete will use the key to find and delete the data object within the object
Let's apply these update and delete operations to the application.
Step 7: Update and delete tasks from the Task List view
You've already done some of the work required for updating and deleting a task. If you look
at the Task List view in the application, you'll notice that each task has a check box and
a Delete button. The check box has an updateTask embedded into the markAsCom-
plete event handler, and the Delete button has a deleteTask embedded into the re-
move event handler.
All that's left to do is to insert the procedures for updating and deleting the object store
into their respective updateTask and deleteTask function definitions. Because not
all browsers support IndexedDB, you'll also insert a Web SQL fallback. Add the code from
this listing right beneath the code from the previous listing..
Search WWH ::

Custom Search