mercredi 12 août 2015

Ember data - get first of collection

Okay, it's shocking how poorly documented this is and that I cannot find an answer quickly.

How to I get the first object of a collection in ember?

This is the collection:

this.store.query('review', { order_id: params.id })

I want the first record and only the first record (not as a collection) to use in my template.

None of these work:

// First attempt
this.store.query('review', { order_id: params.id })[0];
// Second attempt
this.store.query('review', { order_id: params.id }).get('firstObject');

// Third attempt
var r;
this.store.query('review', { order_id: params.id }).then(function(results) {
  r = results.get('firstObject');
});

Aucun commentaire:

Enregistrer un commentaire