Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember-Data callback when findAll finished loading all records

With ember-data I'm loading all records of a model with:

App.adapter = DS.Adapter.create({
  findAll: function(store, type) {
      var url = type.url;
      jQuery.getJSON(url, function(data) {
          var ids = data.map(function(item, index, self){ return item.id });
          store.loadMany(type, ids, data);
      });
  }
});

The didLoad method is called when each of the record has finished loading. Is there a method to call when all records have finished loading?


EDIT

Model:

App.Article  = DS.Model.extend({

  title: DS.attr('string'),
  content: DS.attr('string'),


  checkIsLoaded: function() {
      if (this.get('isLoaded')){
         console.log('loaded!'); // outputs `loaded` for each record
      }
  }.observes('isLoaded')

});
like image 860
Panagiotis Panagi Avatar asked Apr 05 '12 15:04

Panagiotis Panagi


1 Answers

Yes, you can use findQuery, and then observe .isLoaded property on the ModelArray.

e.g:

load: ->
    @set 'data', @get('store').findQuery App.MyModel, { q: '...' }

And have the observation:

loadingComplete: ( ->
    @doSomeStuff() if @getPath 'data.isLoaded'
).observes 'data.isLoaded'
like image 141
Mike Aski Avatar answered Jan 02 '23 19:01

Mike Aski