vendredi 3 juillet 2015

Filter through a hasMany connection

I have a route and a destination model and would like to create a filteredRoutes computed property which only contains routes which have a destination.name with the value of selectedDestination. I can't figure out the last puzzle piece to do that. How can I filter that?

controller.js

filteredRoutes: Ember.computed('model.routes', 'selectedDestination', function() {
    var selectedDestination = this.get('selectedDestination');
    var routes = this.get('model.routes');

    if(selectedDestination) {
      routes = routes.filter(function(route) {
      // ????
      });
    }
  }),

app/destination/model.js

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string')
});

app/route/model.js import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  destinations: DS.hasMany('destinations', { async: true })
});




Aucun commentaire:

Enregistrer un commentaire