I have a situation where isLoaded on a DS.RecordArray changes to true but the content, length property of the RecordArray is still empty, 0 at that time and only changes later.
Sample Code(coffeescript):
@set('followRequests', App.FollowRequests.find())
...
whenDataLoads: (->
console.log @get('followRequests.isLoaded')
console.log @get('followRequests.length')
@set('content', @get('followRequests').toArray() )
).observes('followRequests.isLoaded')
The first log statement is true while the second is 0 and the template which uses this data is empty. When I see the actual AJAX request I see that the request does return an array of records. And the length and content of the RecordArray do change some time later as seen in the Browser console by doing:
App.Router.myController.get('followRequests').get('length')
---> 12
However this code(below) does populate the content in the template, but it runs 12 times...
whenDataLoads: (->
console.log @get('followRequests.isLoaded')
console.log @get('followRequests.length')
@set('content', @get('followRequests').toArray() )
).observes('followRequests.length')
What's the right way to know when the RecordArray is completely populated...??
Since the time Ember.js uses promises you can do this
App.FollowRequests.find().then(function () {
// This callback will fire when array is loaded
});
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