jquery - Javascript - Dynamic .filter() - Json File -
i need hint. i'm not programmer, take chances automating processes, excuse me if question basic.
i'm working google maps api, , @ point need accomplish filter target content of infowindow
.
i have map various filters, apply markers , should extend content of infowindow
.
i have json
contents of infowindow
, , applying filter way: (ards = json file)
var as=$(ards).filter(function (i,n){ return n.erb===marker.gettitle(); }); (var i=0;i<as.length;i++) { .... }
ok, works, need add more variables filter.
i own these markers filters.
var cluster = $( "#cluster-select" ).val(); var client = $('#cli_re-select').val(); var type_cli = $('#type_cli-select').val(); var type_recla = $('#type_recla-select').val();
i put 4 exemplify, has around 10 filters.
the filters independent, can select 1 @ time.
i made way:
var combine = []; combine = []; if(cluster !== '0') { combine.push('&& n.desc_cluster === ' + '"' + cluster + '"'); } if(cliente_recente !== '0') { combine.push('&& n.client_re === ' + '"' + client + '"'); } if(tipo_cli !== '0') { combine.push('&& n.type_cli === ' + '"' + type_cli + '"'); } if(tipo_reclama !== '0') { combine.push('&& n.type_recla === ' + '"' + type_recla + '"'); } var filter_add; filter_add = "1 = 1"; for(var i=0;i<combine.length;i++){ filter_add += combine[i]; }
the result is: 1 = 1 && n.desc_cluster === "cta" && n.type_cli === "soho"
and added variable in filter:
var as=$(ards).filter(function (i,n){ return n.armario_erb===marker.gettitle() && filter_add; });
but did not work, not apply values result, first part.
my question is, how else can accomplish dynamic filter?
thanks.
as each filter independent, need flag each filter specifying if criteria checked or not. if flag checked , result of criteria filterflag (this filter function). :
var cluster = $( "#cluster-select" ).val(); var client = $('#cli_re-select').val(); var as=$(ards).filter(function (i,n){ var filterflag=true; if(cluster !='0'){ // code cluster filterflag = filterflag && ____ // add result of above code : true or false } if(client != '0' ){ // code here filterflag = filterflag && ____ // add result of above code : true or false } //......same others //...... return filterflag; });
let me know if dont understand this. need code can directly fix it.
Comments
Post a Comment