Feature: Delete a project
Let's add a delete button to our form for the feature Delete a project
.
Let's make a change to ProjectView
and add a new event to the events
hash, called delete
, which calls the delete
method. We add a delete
method, which destroys the model and removes ProjectView
. We then call repository
, removing RepositoryListView
.
events: { ... "click button.delete": "delete", }, delete: function () { this.model.destroy(); this.remove(); this.repository({editMode:false}); },
Let's make a change to ProjectListView
and add a collection
event handler to initialize
. The event handler calls the remove
method when an item is removed. The remove
method grabs the model's attributes and searches the Projects
collection, removing the item when finding it.
initialize: function () { ... this.collection.on("remove", this.remove, this); }, remove: function (removedModel) { var removed = removedModel.attributes; ...