mardi 30 octobre 2018

How would I filter using filterBy for a multiple values selected and use mapBy to manipulate the array?

on my template I do have a dropdown that may select a multiple values Example, zoneNameOne, zoneNameTwo. My component.js has a code that would filter a records based on the multiple values that had been selected from the dropdown.

jobOrderCityNames: computed('selectedZoneOrCityName', 
 'jobOrders.@each.zoneName', 'jobOrders.@each.cityName', function() {
  let selectedZoneOrCityName = this.get('selectedZoneOrCityName');
  if (selectedZoneOrCityName) {
    return this.get('jobOrders').filterBy('zoneName', selectedZoneOrCityName).mapBy('cityName');
   } else {
    return [];
  }
}),

The jobOrders return a array of objects below. [{id: 123, type: "job-orders",…}, {id: 124, type: "job-orders",…}]

My problem: I can't filter the array of objects on a multiple values selected from the dropdown. Please see the code above

My question: How can I filter the array of objects on a multiple values and mapBy the property name?

Please help me, any response is much appreciated.




Aucun commentaire:

Enregistrer un commentaire