Remove book entry

Next we will work on the book deletion.

We begin at the model. We add a removeBook function. It is similar to the ticker removal from the TwentyFive timer. = function(isbn) {
 2  for(var i=0,; i<len; i++) {
 3    var book =[i];
 4    if (book.isbn === isbn) {
 5, 1);
 6      return; // remove only the first match record
 7    }
 8  }

When the delete button is clicked, we remove the book from the model data. Then render the list again to reflect the changes.

The click event of delete button. Since the book entry is created dynamically, normal click event doesn’t work. We need the following jQuery delegate method.

1app.view.listElement.delegate('.delete-btn', 'click', function(){
2  var isbn = $(this).data('isbn') + ""; // ensure we are dealing with string type.
4  app.view.renderList();

Note: The click event equivalent.

2// is equivalent to
3$(element).bind('click', handler);

And delegate event is very similar to the bind event:

1$(element).delegate(selector, 'click', handler);

What’s next? We’re going to take a look at “Taking the inputs data”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content