HTML and CSS Reference
In-Depth Information
var result = [];
We then use the helper function to return the object store for the specified type:
var storageItem = getStorageObject(type);
The object store will contain a set of properties representing all the saved objects for this
type, therefore we iterate through them and add each value to the results array using the
push method:
$.each(storageItem, function(i, v) {
result.push(v);
});
The result is then returned to the success callback:
successCallback(result);
The findAll method can now be invoked from the tasks-controller.js file. The functionality
to call findAll and add all the results to the table will be included in a new public method
after the init method called loadTasks :
loadTasks : function() {
storageEngine.findAll('task', function(tasks) {
$.each(tasks, function(index, task) {
$('#taskRow').tmpl(task ).appendTo( $(taskPage ).find( '#tblTasks tbody'));
});
}, errorLogger);
}
This performs the call to findAll , and then, in the success callback, iterates through the res-
ults one by one and adds them to the table using the template.
Now, inside the tasks.html page, add a call to this method after the call to init :
$(document).ready(function() {
tasksController.init($('#taskPage'));
tasksController.loadTasks();
})
If you reload tasks.html, any saved tasks should load into the table.
We can now add the delete method to the storage engine.
delete : function(type, id, successCallback, errorCallback) {
if (!initialized) {
Search WWH ::




Custom Search