3
I’m in need of a tip. I’m not a programmer, but I like to risk automating processes, sorry if the question is too basic.
I’m working with the Google Maps API, and at a certain point I need to perform a filter to segment the contents of my InfoWindow
.
I have a map with several filters, which apply to the markers and should extend to the contents of InfoWindow
.
Doing it this way, I’m picking it up the full content of JSON ards
and printing on InfoWindow
, without segmenting the filters.
// Busca armario no segundo arquivo JSON
var as=$(ards).filter(function (i,n){
return n.ARMARIO_ERB===marker.getTitle();
});
for (var i=0;i<as.length;i++)
{ .... }
I have a series of filters, which target my markers, but I would like in the content of InfoWindow
only records referring to filters appear.
//informação dos selects
var cluster = $( "#CLUSTER-select" ).val();
var cliente_recente = $('#cli_re-select').val();
var tipo_cli = $('#tipo_cli-select').val();
var tipo_reclama = $('#tipo_recla-select').val();
I would like a way to apply the filters at this point, testing if they are different from ZERO applies in .filter
.
// Busca armario no segundo arquivo JSON
var as=$(ards).filter(function (i,n){
return n.ARMARIO_ERB===marker.getTitle() && n.DESC_CLUSTER===cluster;
});
Go adding the &&
as filters are selected.
Is there any more practical way to do this without having to create a lot of IF
nested testing the combinations?
I can select a filter only, or two, three and so on, are independent. There is a sample of only 4, I have around 10. How can I do this more efficiently?
----------------- Updating ----------------
I came back from lunch with an idea, but it didn’t work right.
I created the following structure:
var combina = [];
combina = [];
if(cluster !== '0') {
combina.push('DESC_CLUSTER;' + cluster);
}
if(cliente_recente !== '0') {
combina.push('CLIENTE_RECENTE;' + cliente_recente);
}
if(tipo_cli !== '0') {
combina.push('TIPO_CLIENTE;' + tipo_cli);
}
if(tipo_reclama !== '0') {
combina.push('TIPO_RECLAMACAO;' + tipo_reclama);
}
var filtro_add;
filtro_add = "1 = 1";
for(var i=0;i<combina.length;i++){
var split;
split = combina[i].split(';');
filtro_add += " && n." + split[0] + " === " + '"' + split[1] + '"';
}
Result of filtro_add
: 1 = 1 && n.DESC_CLUSTER === "CURITIBA" && n.TIPO_CLIENTE === "SOHO"
And added this variable to my filter:
// Busca armario no segundo arquivo JSON
var as=$(ards).filter(function (i,n){
return n.ARMARIO_ERB===marker.getTitle() && filtro_add;
});
But it didn’t work, it doesn’t apply the values to the result. If I put the fields in hand it works. Example:
return n.ARMARIO_ERB===marker.getTitle() && n.DESC_CLUSTER === "CURITIBA";
How can I transform this String
?
----------------- Updating ----------------
After a lot of research, I found an alternative, but with a bad performance and possible problems, the staff does not recommend much use.
Through the eval()
I added it to the search field.
String looked like this: filtro_add
: n.ARMARIO_ERB===marker.getTitle() && n.DESC_CLUSTER === "CURITIBA"
// Busca armario no segundo arquivo JSON
var as=$(ards).filter(function (i,n){
return eval(filtro_add);
});
Works, but with poor performance.
Is there any other alternative?
Thank you.