HTML and CSS Reference
In-Depth Information
errorCallback('storage_api_not_initialized', 'The storage engine has not been initialized');
} else if (!initializeObjectStores[type]) {
errorCallback('store_not_initialized', 'The object store '+type+' has not been initialized');
}
var storageItem = getStorageObject(type);
if (storageItem[id]) {
delete storageItem[id];
localStorage.setItem(type, JSON.stringify(storageItem));
successCallback(id);
} else {
errorCallback("object_not_found","The object requested could not be found");
}
}
The delete implementation is straightforward; the one aspect that may be new is the line:
delete storageItem[id];
It is possible to delete a property (and therefore its value) from an object by using the delete
keyword. Since we are storing each item as a property of an object, we can delete the indi-
vidual items with this technique. After invoking this, the property specified is undefined .
When the delete button is clicked we need to know which task needs to be deleted. We
therefore need to update the delete button so that it knows which task it relates to. Change
the following line in the template:
<a href="#" class="deleteRow">Delete</a>
to
<a href="#" class="deleteRow" data-task-id="${id}">Delete</a>
This uses a custom data attribute to keep track of which task each delete button is respons-
ible for.
Now change the delete implementation in tasks-controller.js from this:
$(taskPage).find('#tblTasks tbody').on('click', '.deleteRow',
function(evt) {
$(evt.target).parents('tr').remove();
});
to this:
$(taskPage).find('#tblTasks tbody').on('click', '.deleteRow',
Search WWH ::




Custom Search