I have a simple part of my Ember application that's supposed to draw a list of books. The issue is that if the user visits the list before the books are loaded from the server, the list will be empty. Even after the data finishes loading, the list will still be empty.
What methods does Ember have to to refresh the view after data is loaded? And where would be the appropriate place to put this code? Here's what my code looks like:
Route:
App.MyRoute = Ember.Route.extend({
model: function() {
return App.store.find(App.Book); // get books from the server
}
});
Template:
{{#each book in model}}
<li {{ bindAttr data-book-id="book.id" }}>
<span>{{ book.name }}</span>
</li>
{{/each}}
For the record, I would like to do something like this:
{{#if model.get('isLoaded')}}
{{#each book in model}}
<li {{ bindAttr data-book-id="book.id" }}>
<span>{{ book.name }}</span>
</li>
{{/each}}
{{else}}
<span>Loading books...</span>
{{/#if}}