HTML and CSS Reference
In-Depth Information
Due to the fact we are not going to add an index to the properties on task, we have no option
but to loop through the objects ourselves and determine those that match:
findByProperty : function(type, propertyName, propertyValue, successCallback, errorCallback) {
if (!database) {
errorCallback('storage_api_not_initialized', 'The storage engine has not been initialized');
}
var result = [];
var tx = database.transaction(type);
var objectStore = tx.objectStore(type);
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
if (cursor.value[propertyName] == propertyValue) {
result.push(cursor.value);
}
cursor.continue();
} else {
successCallback(result);
}
};
}
The complete implementation of the IndexedDB storage engine should now look like this:
storageEngine = function() {
var database;
var objectStores;
return {
init : function(successCallback, errorCallback) {
if (window.indexedDB) {
var request = indexedDB.open(window.location.hostname+'DB');
request.onsuccess = function(event) {
database = request.result;
successCallback(null);
Search WWH ::




Custom Search