backbone.js - How to remove an item from a collection and collection view by not re-rendering the whole list? Is it possible? -
hi i'm bit new backbone.js
is there way remove item (and item) collection , not have refresh list. instead remove item view , collection , no refresh/re-rendering happens view collection. or possible?
here's snippet of code:
var datemodel = backbone.model.extend({ defaults: function() { return { index: '', valuefrom: '', valueto: '', status: '', showtext: '', text: '' } }, }); var datelist = backbone.collection.extend({ model: datemodel }); var datelist = new datelist(); var dateview = backbone.view.extend({ model: new datemodel(), ... }); var datelistview = backbone.view.extend({ model: datelist, el: $('#date-list-container'), initialize: function() { this.listento(this.model, 'add', this.render); this.listento(this.model, 'remove', this.render); this.listento(this.model, 'reset', this.render); }, render: function() { // code rendering here... _.each(this.model.models, function(date){...}); } });
you can changing event listener this.render
custom listener function receives model removed argument and, instead of re-rendering entire view, removes html element representing model view. way, don't have re-render entire view, can costly, alter part has changed.
for example, line:
this.listento(this.model, 'remove', this.render);
would replaced different event handler function received arguments remove event:
remove (model, collection, options) — when model removed collection.
so might have event listener function such this:
modelremoved: function(model, collection, options) { // code find html element 'model' , remove dom }
and use event handler remove events:
this.listento(this.model, 'remove', this.modelremoved);
Comments
Post a Comment