I have this filter in jQuery:
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 nomev = value[0].split('- ')[1].substr(1, (value[0].split('|')[0].split('- ')[1].substr(1).length -1));
var precov = value[0].split('|')[1];
Array.prototype.push.apply(aeroportosida, this.data.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, dataa.filter(function(pesquisa){
var respostas = 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 = respostas;
return respostas.length > 0;
}));
});
}else if(value.length == 0){
return this;
}
this.data = aeroportosida;
return this;
}
It filters according to a list of checkbox
. When I select only 1 checkbox
it filters normally, but when I select more than 1 it does not filter, and returns null
.
In the value parameter I pass the values of checkbox
selected to array
.
Does anyone know why it can not filter more than 1?
I need to filter a JSON according to the array data. For example if I pass two values in the array I have to filter json by the first value then refile json by the second value.
I made this filter over this JSFIDDLE that came out this question
Update: ERROR HAPPENS WHEN I USE
var respostas = pesquisa.trecho[0].voo.filter(function(voos){
WITHIN
Array.prototype.push.apply(aeroportosida, dataa.filter(function(pesquisa){
Example: link
Note that no: {"sqTrecho":1,"voo":[]}
voo:
can not return []