dimanche 5 juillet 2015

computed property to collect hasMany data

A route hasMany departuredates. I'd like to create a computed property which collects the value attribute of all departuredates and returns a string which comma separates them and adds the end date (which is departuredate.value + route.duration) of each.

Examples:

  • "01.01.2015 - 05.01.2015"
  • "02.03.2016 - 12.03.2016, 02.04.2016 - 12.04.2016"

How can I do this? And is departuredates.@each.value the correct property to use?

app/route/model.js

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  duration: DS.attr('number'),
  departuredates: DS.hasMany('departuredate', { async: true }),

  departuredateText: Ember.computed('departuredates.@each.value', function() {
    // ???
  })
});

app/departuredate/model.js

import DS from 'ember-data';

export default DS.Model.extend({
  value: DS.attr('date')
});




Aucun commentaire:

Enregistrer un commentaire