Created
February 24, 2013 21:12
-
-
Save glynrob/5025644 to your computer and use it in GitHub Desktop.
Indexed DB display all rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function displayRows(store) { | |
if (typeof store == 'undefined') | |
store = getObjectStore(DB_TABLE_NAME, 'readonly'); // no table passed so use the default one | |
var listcontainer = $('.listcontainer'); | |
listcontainer.empty(); // clear existing data in the container | |
var req; | |
req = store.count(); | |
req.onsuccess = function(evt) { | |
// listing completed | |
}; | |
req.onerror = function(evt) { // error - display error to the user | |
displayActionFailure(this.error); | |
}; | |
req = store.openCursor(); | |
req.onsuccess = function(evt) { | |
var cursor = evt.target.result; | |
if (cursor) { // If the cursor is pointing at something, ask for the data | |
req = store.get(cursor.key); | |
req.onsuccess = function (evt) { | |
var value = evt.target.result; | |
var list_item = '<div id="a' + cursor.key + '" class="listitem">' + value.title + ' <a class="delbtn"><img src="icon_delete_small.png" alt="" border="0" /></a></div>'; // create html for each element | |
listcontainer.append(list_item); | |
}; | |
cursor.continue();// Move on to the next object in store | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment