samedi 10 janvier 2015

Ember.js: Determine current route from the view

I have two routes, one for unread books and another for read books. Both routes share the same template:



App.UserPanelBooksIndexRoute = Ember.Route.extend({
templateName: 'userPanel/index',
model: function() {
return this.store.filter("book", function(book) {
return !book.get("isRead");
});
},
readBooks: false
});

App.UserPanelBooksSoldRoute = Ember.Route.extend({
templateName: 'userPanel/index',
model: function() {
return this.store.filter("book", function(book) {
return book.get("isRead");
});
},
readBooks: true
});


Within the view I render the books and if there are no unread books I would like to display "Sorry, no unread books", and if there are no read books I would like to display "Sorry, no read books" message. Except my method with setting a boolean in the route doesn't work (readBooks always evaluates to true in the view):



{{#if model.length}}
{{#each book in model itemController='book'}}
<ul>{{book.title}}</ul>
{{/each}}
{{else}}
{{#if readBooks}}
<h1>"Sorry, no sold books"</h1>
{{else}}
<h1>"Sorry, no unsold books"</h1>
{{/if}}
{{/if}}

Aucun commentaire:

Enregistrer un commentaire