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')
});
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With