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

159
Views
Objeto dinámico js con matrices dinámicas

Hola, estoy creando un filtro dinámico como este.

Filtro 1 --propiedad 1 --propiedad 2 --propiedad 3

Filtro 2 --propiedad 1 --propiedad 2 --propiedad 3

ese es el codigo

 var js_filter = {}; var creators_cat = []; $('.filter-item input').on('change',function (e) { var filter_type = $(this).attr('name'); var filter_term = $(this).val(); creators_cat.push( filter_term ); js_filter["'"+filter_type+"'"] = creators_cat; console.log(js_filter); })

y esa es una respuesta que recibo

 {'filter-product_cat[]': Array(4), 'filter-brands': Array(4)} 'filter-brands': (4) ['32', '29', '23', '36'] 'filter-product_cat[]': (4) ['32', '29', '23', '36'] [[Prototype]]: Object

como puede ver, las claves de matriz se agregan dinámicamente, pero los valores son los mismos para ambas claves.

Y necesito agregarlos por separado. Estuve buscando una respuesta por un tiempo y no encontré algo similar.

Agradecería cualquier ayuda.

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

0

No debería estar presionando en una matriz global. Cada entrada de filtro debe tener su propia matriz de valores.

Compruebe si ya hay un elemento del objeto js_filter para el filter_type actual. Si no, créelo como una matriz vacía. Luego inserte el valor actual en la matriz.

 $('.filter-item input').on('change', function(e) { var filter_type = $(this).attr('name'); var filter_term = $(this).val(); if (!js_filter[filter_type]) { js_filter[filter_type] = []; } js_filter[filter_type].push(filter_term); console.log(js_filter); })
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!