When using ember data, the find method returns a proxy array. You can observe the isLoaded field on this object.
var data = App.store.find(App.Model, {}); data.addObserver('isLoaded', function() { if (data.get('isLoaded')) { .... } });
But remember to clear your observer through removeObserver.
I added this utility to the built-in array of ember data records.
DS.RecordArray.reopen({ onLoad: function(callback) { if (this.get('isLoaded')) { callback(this); } else { var that = this; var isLoadedFn = function() { if (that.get('isLoaded')) { that.removeObserver('isLoaded', isLoadedFn); callback(that); } } this.addObserver('isLoaded', isLoadedFn); } return this; } }
So now you can just do
App.store.find(App.Model, {}).onLoad(function(data) { .... });
You can also do something like
init: function() { this.set('data', App.store.find(App.model, {})); }, onData: function() { if (this.get('data.isLoaded')) { ... } }.observes('data.isLoaded')
source share