0
Hello.
I have 10 filters for a single json object:
var filtro1 = function(value, selecionado){
var data = JSON.parse(JSON.stringify(json.aPesquisa));
var result = data.filter(function(pesquisa){
...
});
return result;
}
var filtro2 = function(value, selecionado){
var data = JSON.parse(JSON.stringify(json.aPesquisa));
var result = data.filter(function(pesquisa){
...
});
return result;
}
var filtro3 = function(horamin, horamax){
var data = JSON.parse(JSON.stringify(json.aPesquisa));
var result = data.filter(function(pesquisa){
...
});
return result;
}
var filtro4 = function(value, selecionado){
var data = JSON.parse(JSON.stringify(json.aPesquisa));
var result = data.filter(function(pesquisa){
...
});
return result;
}
...
And so on and so forth. As you can see, each filter works separately, that is, if I filter with filtro1 and then with filtro2 it displays only the filter.
Would there be some way I could put these filters together?
I thought of using an array with the selected filters:
var filtros = ["filtro1, "filtro2", "filtro6", "filtro9", "filtro10"];
But I couldn’t.
The idea and connect the filters.
But are 10 filters that produce 10 results or should 10 filters that produce 1 result? As the code you presented 10 results, but with the text implies that it should be only one. Confusing.
– Woss
you meant result = json.filter(func() .. ). filter(func2() ...)... ?
– wryel
@Andersoncarloswoss are 10 filters that produce a result. So: I have a json and I want to filter it by color, size, quantity, price all together. The way it is I can filter each one separately. But I need only 1 result
– usuario
Have you ever thought of, instead of
json.filter
in all, put the result from the previous filter? For example:var filtro2 = filtro1.filter()
– Woss
Thus it would also be good to make an array with all filter functions apply them with a cycle, always using the result of the previous iteration
– Isac