samedi 14 février 2015

Backbone.js: Remove item from view when removed from collection


I'm using Backbone.js. I am listen to the "add" event of my collection



this.listenTo(this.collection, "add", this.addOne);


and it will append the view object like this:



addOne: function (as) {
var v = new XUView({model: as}).render();
$(v.el).prependTo($('#object-list')).hide().fadeIn().slideDown();
}


Now I want to automatically remove objects from the view if the item has been deleted from the collection. I am listening on the "remove" event:



this.listenTo(this.collection, "remove", this.removeOne);


And I tried several things for the remove function, but none of them did the job. The removeOne function is triggered correctly, but as I said, without effect. How can I remove the view object from my frontend?


I already tried:



XUView.remove(XUView.where(as));

XUView.remove(as);

this.collection.remove(as);

this.collection.remove(this.collection.where(as));




Aucun commentaire:

Enregistrer un commentaire