HTML and CSS Reference
In-Depth Information
successCallback(objs);
}
And the following is the implementation in tasks-indexeddb.js:
saveAll : function(type, objs, successCallback, errorCallback) {
if (!database) {
errorCallback('storage_api_not_initialized', 'The storage engine has not been initialized');
}
var tx = database.transaction([type], "readwrite");
tx.oncomplete = function(event) {
successCallback(objs);
};
tx.onerror = function(event) {
errorCallback('transaction_error', 'It is not possible to store the object');
};
var objectStore = tx.objectStore(type);
$.each(objs, function(indx, obj) {
if (!obj.id) {
delete obj.id ;
} else {
obj.id = parseInt(obj.id)
}
var request = objectStore.put(obj);
request.onsuccess = function(event) {
obj.id = event.target.result
}
request.onerror = function(event) {
errorCallback('object_not_stored', 'It is not possible to store the object');
};
});
}
Notice that we only create one transaction and then add multiple requests to it: one for each
task. It is not until all these requests complete that the transaction is considered complete,
and the client is notified of the success.
Search WWH ::




Custom Search