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

216
Views
Cómo seleccionar el elemento de la matriz (matriz de objetos) en función de un atributo particular

Tengo la siguiente matriz de objetos. Estoy tratando de filtrar los productos por tamaño de tal manera que todos los productos del tamaño específico seleccionado por el usuario solo se representen como normalmente sucede en un sitio web de comercio electrónico.

Entonces, por ejemplo, si selecciono el tamaño S, solo quiero que se reproduzcan los productos que tienen el tamaño "S" disponible en el inventario.

part1 para tomar el tamaño recogido por el usuario

 const sizeFilterHandler = (event) => { console.log(event.target.value); setSizeFilter(event.target.value); };

part2 para tomar el tamaño recogido por el usuario

 onChange={sizeFilterHandler} className="form-select mb-3" aria-label=".form-select-lg example" > <option selected>Size</option> <option value="S">S</option> <option value="M">M</option> <option value="L">L</option> <option value="XL">XL</option> <option value="XXL">XXL</option> <option value="XXXL">XXXL</option> </select>
 "inventoryInfo": [ { "skuId": 47638228, "label": "S", "inventory": 227, "available": true }, { "skuId": 47638227, "label": "M", "inventory": 330, "available": true }, { "skuId": 47638224, "label": "L", "inventory": 325, "available": true }, { "skuId": 47638225, "label": "XL", "inventory": 313, "available": true }, { "skuId": 47638226, "label": "XXL", "inventory": 146, "available": true }, { "skuId": 47638223, "label": "3XL", "inventory": 80, "available": true } ],
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debería poder usar la función de filtro de matriz. Algo como

 inventoryToDisplay = inventoryInfo.filter(inventoryItem => inventoryItem.label === event.target.value)
about 4 years ago · Juan Pablo Isaza Report

0

Filtro y mapa

 return ( <div className="App"> {/* XL is your value from setFilter */} {inventoryInfo .filter((item) => item.label === 'XL' && item.available === true) .map((element, index) => ( <> <div key={index}>{element.skuId}</div> <div key={index}>{element.label}</div> <div key={index}>{element.inventory}</div> <div key={index}>{element.available}</div> </> ))} </div> );
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!