Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
¿Cómo aplicar filtros juntos?

Tengo marcadores en un mapa de Google con filtros desplegables, y estos filtros funcionan perfectamente bien individualmente. Sin embargo, quiero que el filtro considere las tres listas desplegables a la vez.

Aquí está mi código: https://jsfiddle.net/h4cv57tb/

De alguna manera, las 3 funciones de filtro deberían fusionarse, pero desafortunadamente no tengo idea de cómo...

Estas son las funciones de filtro que deben fusionarse:

 //Filter by type filterMarkers = function(category) { for (i = 0; i < gmarkers1.length; i++) { marker = gmarkers1[i]; // If is same category or category not picked if (marker.category == category || category.length === 0) { marker.setVisible(true); } // Categories don't match else { marker.setVisible(false); } } } //FILTER by ripening time filterMarkersEres = function(eres) { for (i = 0; i < gmarkers1.length; i++) { marker = gmarkers1[i]; var ereshonap = marker.eres; // If is same category or category not picked if (ereshonap.includes(parseInt(eres)) || eres.length === 0) { // marker.setVisible(true); } // Categories don't match else { marker.setVisible(false); } } } //FILTER by place filterMarkersHely_tipus = function(hely_tipus) { for (i = 0; i < gmarkers1.length; i++) { marker = gmarkers1[i]; // If is same category or category not picked if (marker.hely_tipus == hely_tipus || hely_tipus.length === 0) { marker.setVisible(true); } // Categories don't match else { marker.setVisible(false); } } }

¡Gracias de antemano por tu ayuda!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Asegúrese de mirar dónde hay código duplicado y simplemente combine las áreas que son diferentes, si es factible. Para combinar estas funciones en una sola, simplemente combine las condiciones if juntas.

 filterMarkers = function(category = null, eres = null, hely_tipus = null) { for (i = 0; i < gmarkers1.length; i++) { marker = gmarkers1[i]; ereshonap = marker.eres; visible = false; if (category){ if (marker.category == category || category.length === 0) { visible = true; } } if (eres) { if (ereshonap.includes(parseInt(eres)) || eres.length === 0) { visible = true; } } if (hely_tipus) { if(marker.hely_tipus == hely_tipus) { visible = true; } } if (visible) { marker.setVisible(true); } else { marker.setVisible(false); } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!