I've got a model which is being destroyed in a form view, and I need it to also remove the related element from the list view.
in my form view I have
delete: function(){ this.model.destroy(); this.el.remove(); }
and in my list view I have
initialize: function(){ this.model.on('remove',this.delete); }, delete: function(){ alert('delete'); this.el.remove(); this.el.unbind(); }
when I delete the item, the delete in the listView is triggered, but I get an error cannot call method remove of undefined
.
I've also tried $(this.el).remove()
, but no luck.
The listView is added from the collection in another view with
itemCollection.each(this.add); add: function(){ var create = new Myapp.Views.Items({model:item}); $(this.el).append(create.el); }
replace this.el
with this.$el
don't use delete as method name
change from this.model.on('remove',this.delete);
to this.model.on('remove',_.bind(this.delete, this));