Game Development Reference
In-Depth Information
};
req.onerror = function(e) {
// Handle error
};
Finally, we can delete multiple records using a cursor. This is similar to the way we
retrieve objects. As we iterate through the result set using the cursor, we can simply
delete the object at whatever position the cursor is currently on. Upon deletion, the
reference from the cursor object is set to null as shown in the following code snippet:
// 1. Be sure to set the transaction to
readwrite. Else, there will be a nice
// exception raised if we try to delete
readonly data.
var trans = db.transaction(storeName,
"readwrite");
var store = trans.objectStore(storeName);
// 2. specify the range in the data store to
request data from
var keyRange = IDBKeyRange.lowerBound(0);
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();
}
// Here, we could have accessed the
object's primary ID through
// the cursor object in cursor.value.myKey.
However, accessing
// cursor.primaryKey maps to the specific
property name that holds
// the value of the primary key.
store.delete(cursor.primaryKey);
Search WWH ::




Custom Search