javascript - Re-render view without models changed backbone -
i'm rendering view collection of user.when specific attribute(status=online,offline) in user change view correctly show on dom value of attribute changed. if want render view without model in attribute changed or viceversa add view model in wich attribute changed?
this code send view collection users status online:
var user_on=models.utenti.filter(function(model){ return model.get('status') === "on"; }); var users_online = new usercollection(user_on); var page=new homelistuser({model:users_online}); this.changepage(page);
and view:
var homelistuser = backbone.view.extend({ tagname: "ul", id: "list", template: handlebars.compile(template), initialize: function () { models=this.model; this.model.bind("reset", this.render, this); $(window).on('orientationchange', this.onorientationchange); }, render: function (eventname) { $(this.el).empty(); _.each(this.model.models, function (ad) { $(this.el).append(new singleuserview({ model: ad }).render().el); }, this); return this; },
you filter online users in render
function of view, believe called users_online
collection model
in it, so:
model.reset(model.filter(function(model){ return model.get('status') === 'on'; }));
or maybe filter elements out append singleuserview
s
_.each(this.model.models, function (ad) { if (ad.get('status') !== 'on') return; $(this.el).append(new singleuserview({ model: ad }).render().el); }, this);
Comments
Post a Comment