Game Development Reference
In-Depth Information
}
// …
var req = store.openCursor(keyRange);
req.onsuccess = function(e) {
var cursor = e.target.result;
// Before we continue, we need to make sure
that we
// haven't hit the end of the result set
if (!cursor) {
callback();
}
var todoItem = inflatObject(TodoItem,
cursor.value);
// We could even call methods on the new
inflated object
var itemElement = todoItem.toHTML();
document.body.appendChild(itemElement);
todoItem.myKey == cursor.myKey; // True
todoItem.task == cursor.task; // True
todoItem.completed == cursor.completed; //
True
todoItems.push(todoItem);
// Tell the cursor to fetch the next result
cursor.continue();
};
Deleting elements
To remove specific elements from a data store, the same principles involved in re-
trieving data apply. In fact, the entire process looks fairly identical to retrieving data,
only we call the delete function on the object store object. Needless to say, the trans-
action used in this action must be readwrite, since readonly limits the object so that
no changes can be done to it (including deletion).
The first way to delete an object is by passing the object's primary key to the delete
function. This is shown as follows:
Search WWH ::




Custom Search