JSFiddle - React, Tailwind, and code Playground
HTML
<div id="result"></div>
JavaScript
var json = {
"aereoPesquisa": [
{
"dsObservacao": null,
"trecho": [
{
"sqTrecho": 1,
"voo": [
{
"aeroportoOrigem": {
"sgIata": "CGH",
},
"vooTarifa": {
"tarifa": {
"vlTotal": 1937.41
}
},
},
{
"aeroportoOrigem": {
"sgIata": "MCO",
},
"vooTarifa": {
"tarifa": {
"vlTotal": 1626.27
}
},
}
]
}
]
},
{
"dsObservacao": null,
"trecho": [
{
"sqTrecho": 1,
"voo": [
{
"aeroportoOrigem": {
"sgIata": "GRU",
},
"vooTarifa": {
"tarifa": {
"vlTotal": 2967.31
}
},
},
{
"aeroportoOrigem": {
"sgIata": "GIG",
},
"vooTarifa": {
"tarifa": {
"vlTotal": 137.41
}
},
}
]
}
]
}
]
};
var Filtro = function () {
this.data = JSON.parse(JSON.stringify(json.aereoPesquisa));
}
var aeroportosida = [];
Filtro.prototype.filtroAereoNomeIda = function(value){
var dataa = JSON.parse(JSON.stringify(this.data));
aeroportosida = [];
if(value.length == 1){
var nm = value[0].split('- (')[1].split('|')[0];
var nomev = nm.substr(0,(nm.length - 1));
var precov = value[0].split('|')[1];
Array.prototype.push.apply(aeroportosida, dataa.filter(function(pesquisa){
var resposta = pesquisa.trecho[0].voo.filter(function(voos){
var nome = voos.aeroportoOrigem.sgIata;
var preco = voos.vooTarifa.tarifa.vlPagamento;
return nome == nomev && preco == precov;
});
pesquisa.trecho[0].voo = resposta;
return resposta.length > 0;
}));
}else if(value.length > 1){
$.grep(value, function(n, i){
var nm = n.split('- (')[1].split('|')[0];
var nomev = nm.substr(0,(nm.length - 1));
var precov = n.split('|')[1];
Array.prototype.push.apply(aeroportosida,...