mardi 23 juin 2015

Display the first element of a has_many relationship

app/models/product.js

import DS from 'ember-data';

var Product = DS.Model.extend({
  name: DS.attr('string'),
  pictures: DS.hasMany('picture', { async: true })
});

export default Product;

app/models/pictures.js

import DS from 'ember-data';

var Picture = DS.Model.extend({
  url: DS.attr('string'),
  alt: DS.attr('string')
});

export default Picture;

In the product index view I can display all pictures with this code:

{{#each picture in ship.pictures}}
  <img {{bind-attr src=picture.url}} alt="example">
{{/each}}

How can I display just the first picture?




Aucun commentaire:

Enregistrer un commentaire