Nam
Nam

Reputation: 67

ember js count number of records in store

When I try:

return this.store.findAll('book');

The console returns a list of books like:

books/1, books/2, books/3

If I install the ember add-on then in DATA I will have 'book(3)'.

Now How can I show this number to the templates?

Upvotes: 0

Views: 1549

Answers (1)

Timm
Timm

Reputation: 1015

Assuming that your route is looking like this:

export default Ember.Route.extend({
  model() {
    return this.store.findAll('book');
  }
});

you should be able to write the following in your route's template:

<p>Our library has {{model.length}} books!</p>

This should output Our library has 3 books! or similar.

Upvotes: 1

Related Questions