1
I need help with the Json filter with jQuery, I have this code:
var chamaFiltro = function(horaminida){
var pesquisa = {
idamin: horasParaMinutos(horaminida)
};
var filtrados = json.aPesquisa.filter(function(voo) {
voo = JSON.parse(JSON.stringify(voo));
voo.trecho = voo.trecho.filter(function(trecho){
trecho = JSON.parse(JSON.stringify(trecho));
trecho.voo = trecho.voo.filter(function(voos){
return horasParaMinutos(voos.dtPartida.slice(9, 14)) >= pesquisa.idamin;
});
return trecho.voo.length > 0;
});
return voo.trecho.length > 0;
});
console.log(filtrados);
};
It filters a JSON and returns me those that the time is greater than the time selected in a slide range.
If you put a:
console.log(section.flight.);
In place of:
Stretch.voo.length > 0;
You can see on the console that it filters normally but when I try to give a return it returns all data up to those that are less than the time of the slide range.
Does anyone know how to get only the filtered data back?
When calling the function it only returns the filtered data?
called Filter(horaminida);
Json:
{
"aPesquisa":[
{
"dsObservacao":null,
"trecho":[
{
"sqTrecho":1,
"voo":[
{
"dtPartida":"20170620 11:20",
"dtChegada":"20170620 16:40"
}
]
},
{
"sqTrecho":2,
"voo":[
{
"dtPartida":"20170627 04:10",
"dtChegada":"20170627 07:40"
},
{
"dtPartida":"20170627 14:15",
"dtChegada":"20170627 17:40"
}
]
}
]
},
{
"dsObservacao":null,
"trecho":[
{
"sqTrecho":1,
"voo":[
{
"dtPartida":"20170720 11:20",
"dtChegada":"20170720 16:40"
}
]
},
{
"sqTrecho":2,
"voo":[
{
"dtPartida":"20170727 04:10",
"dtChegada":"20170727 07:40"
},
{
"dtPartida":"20170727 14:15",
"dtChegada":"20170727 17:40"
}
]
}
]
}
]
}
Assuming I select the time 10:30 at the slide range he should return me only where the hour of dtPartida(dtPartida.slcie(9, 14)) is greater than the time selected in slide range in case 10:30. the return would be so:
[
{
"dsObservacao":null,
"trecho":[
{
"sqTrecho":1,
"voo":[
{
"dtPartida":"20170620 11:20",
"dtChegada":"20170620 16:40"
}
]
},
{
"sqTrecho":2,
"voo":[
{
"dtPartida":"20170627 14:15",
"dtChegada":"20170627 17:40"
}
]
}
]
},
{
"dsObservacao":null,
"trecho":[
{
"sqTrecho":1,
"voo":[
{
"dtPartida":"20170720 11:20",
"dtChegada":"20170720 16:40"
}
]
},
{
"sqTrecho":2,
"voo":[
{
"dtPartida":"20170727 14:15",
"dtChegada":"20170727 17:40"
}
]
}
]
}
]
Follow the code on Jsfiddle
I get it. When I use your code when sliding the slide range it starts to return me so [] know why that? https://jsfiddle.net/8m061jt7/10/
– usuario
@Strange Newtech, here seems to be working properly, returning the two objects
(2) [Object, Object]when sliding the slide. The output you had there was empty?– Woss
when I slide the slide increasing the time it returns the two objects but when I return the slide it returns empty. http://imgur.com/a/TdXic
– usuario