Greg
Greg

Reputation: 1055

Backbone listen to change of collection after ajax

Trying to figure out how to add a listener to my application that will listen for a change or addition to the model or collection - and then re-render the view.

If you look at the console during load of this page, it does a ajax request and add's 659 objects to the collection. Although it does not render the items after it does this request.

https://foodtrucks-c9-gregegan.c9.io/foodtrucks-backbone/

My assumption was to add the following line of code to the AllFoodTrucksView.js initialize() function. But that did not seem to work. this.collection.on("reset add change", this.render);

THanks, Greg

Upvotes: 0

Views: 118

Answers (1)

frajk
frajk

Reputation: 863

If what you want to do is solve the problem of the view not rendering the 659 items after completion of AJAX request, you could do something like:

foodTruckGroup.fetch().done(function() { foodTruckGroupView.render(); });

Upvotes: 1

Related Questions