H
H
Heretic Man2019-03-18 12:58:41
JavaScript
Heretic Man, 2019-03-18 12:58:41

How to organize ajax filtering vue.js according to the criteria specified in the array?

Here is the code.
When changing the selected elements, it is necessary to send a request according to these criteria (The code of the checklisted sheets put into the array already exists and works)

For example, an array in which the keys are set. Using these keys (filter), you need to filter data.json for the similarity of the value in it arr[N].flights[N].airline.code === "KC" and, if so, write this element to another array (arr[ N]) with data.json
filter = ['KC', 'Z9', 'DV'];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-18
@heretic_man

Add the flightsData property, where you will add the data, initially - an empty array.
Display its contents in a template, for example:

<div v-for="item in flightsData">
  <div>Price: {{ item.price }}</div>
  <div v-for="f in item.flights">
    <div>Departure: {{ f.cities.departureCity }}, {{ f.departureTime }}</div>
    <div>Arrival: {{ f.cities.arrivalCity }}, {{ f.arrivalTime }}</div>
  </div>
</div>

What filtering query results might look like (probably it would be more logical to filter on the server and return only the necessary data, think about it):
this.flightsData = response.data.filter(n => val.includes(n.flights[0].airline.code));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question