HTML and CSS Reference
In-Depth Information
$.each(database.objectStoreNames, function(i, v) {
if (v == type) {
exists = true;
}
});
if (exists) {
successCallback(null);
} else {
var version = database.version+1;
database.close();
var request = indexedDB.open(window.location.hostname+'DB', version);
request.onsuccess = function(event) {
successCallback(null);
}
request.onerror = function(event) {
errorCallback( 'storage_not_initalized', 'It is not possible to initialized storage');
}
request.onupgradeneeded = function(event) {
database = event.target.result;
var objectStore = database.createObjectStore(type, { keyPath: "id", autoIncrement: true });
}
}
},
The implementation of this method may look difficult to understand. The first portion of
this method checks whether the object store for this type already exists in the structure of
the database:
$.each(database.objectStoreNames, function(i, v) {
if (v == type) {
exists = true;
}
});
If it does (i.e. this is not the first time the page has been loaded) then we have nothing to
do, and the success callback can be invoked.
Search WWH ::




Custom Search