ember.js - computed property to collect hasMany data -


a route hasmany departuredates. i'd create computed property collects value attribute of departuredates , returns string comma separates them , adds end date (which 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 this? , departuredates.@each.value correct property use?

app/route/model.js

import ds '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 'ember-data';  export default ds.model.extend({   value: ds.attr('date') }); 

not tested should work:

departuredatetext: ember.computed('duration', 'departuredates.@each.value', function() {   return this.get('departuredates').map((departuredate) => {     // compute `enddate` using moment.js or     // (just adding date , number not work).     const enddate = departuredate.get('value') + this.get('duration');      return `${departuredate.get('value')} - ${enddate}`;   }).join(', '); }) 

does make sense?


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -