0

I can't seem to figure out which event to listen to when fetching data for a model. Usually when I'm doing it for a collection, I listen to the sync event. However, it seems like that doesn't work for models.

So, how do I know when my model is done fetching? Which event does it trigger?

Edit: Here's the beginning part of my view that is using the model:

var HomeContent = BaseView.extend({

        initialize: function(options) {
            self = this;
            this.academyID = this.options.parent.academyID;
            this.model = new AcademyModel({academyID: this.academyID});
            this.model.on('sync', function() {
                console.log('sync');
            });
            this.model.fetch();

        }

2 Answers2

0

fetch returns a jQuery promise. Just use something like:

this.model.fetch().done(function() {
  ...
}
ejosafat
  • 401
  • 2
  • 12
0

Another solution is in the docs:

Accepts success and error callbacks in the options hash, which are both passed (model,response, options) as arguments. 
Jonas Geiregat
  • 5,214
  • 4
  • 41
  • 60