Game Development Reference
In-Depth Information
// the data store, a simple readonly
transaction will sufice.
var trans = db.transaction(storeName,
"readonly");
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) {
// cursor IDBCursorWithValue
// key : int
// primaryKey : int
// source : IDBObjectStore
// value : Object
//
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();
}
// If there are still results, let's
process them
// cursor.value === todoItem
// cursor.value.task => "Buy more pizza"
// cursor.value.completed => false
// Since results are plain, typeless object
literals, we need to rebuild
// each object from scratch.
var todoItem = new
TodoItem(cursor.value.task);
todoItem.myKey = cursor.value.myKey;
todoItem.completed = cursor.value.completed;
todoItems.push(todoItem);
// Tell the cursor to fetch the next result
cursor.continue();
Search WWH ::




Custom Search