Boffin
Boffin

Reputation: 569

Re-render backbone view when fetching collection with add:true parameter

I have backbone collection and under some circumstances I am fetching more models into the collection with:

collection.fetch({data: {...}, add: true});

I need view of the collection to be re-rendered when new members arrive. "reset" event is not fired because of add:true parameter hence I see two options.

  1. Bind this.render function to collection's "add" event. This is work but makes render function to be called for each new model arrived from server.
  2. Pass silent:true as fetch parameter and call this.render() explicitly in next line, however at next line data still not arrived, hence render function called with old data.

I haven't found any other way to overcome the issue :( Any advises what should I do in this case?

Upvotes: 0

Views: 807

Answers (1)

Tom Tu
Tom Tu

Reputation: 9593

you can also pass success callback as option to the fetch method and trigger full rerender after successful ajax operation if this is your preferred way of doing it

collection.fetch({data: {...}, add: true, success: function() { ... } }); 

// or reference to function - you get the drill

Upvotes: 2

Related Questions