S
S
sertu2021-10-03 12:00:31
Vue.js
sertu, 2021-10-03 12:00:31

How to make an additional filter?

Good afternoon, there is an example https://codepen.io/djastrodeep/pen/oNwOqzE of filtering only by position, how else to filter by geo. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-10-03
@sertu

<option v-for="item in info">
  {{ item.fieldTypes.geo }}
</option>

It is not right. If the values ​​in fieldTypes.geoare not unique, the options will also be repeated. Why is this? No need. We make a computed property that represents unique values ​​and use it when creating options:
computed: {
  uniqueGeo() {
    return [...new Set(this.info.map(n => n.fieldTypes.geo))];
  },
  ...

<option v-for="n in uniqueGeo">{{ n }}</option>
In the calculated property that represents the filtered data, we add a check for the second value, rewrite it as follows:
computed: {
  filteredOffers() {
    const vacancy = this.searchVacancyName.toUpperCase();
    const geo = this.searchGeo;

    return this.info.filter(n => (
      (!vacancy || n.fieldTypes.vacancyName.toUpperCase().includes(vacancy)) &&
      (!geo || n.fieldTypes.geo === geo)
    ));
  },
  ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question