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

196
Views
¿Cómo mapear la fuente de la imagen en el objeto JSON anidado en reaccionar js?

Tuve un problema al mostrar mis datos de imagen obtenidos de mi API. desde mi consola no mostraba ningún error pero la tarjeta seguía sin mostrar ninguna imagen. Cómo puedo arreglar esto ? Creo que es porque la imagen está registrada como otro objeto a diferencia de la categoría y la marca.

mi ejemplo de datos Json:

 { "count": 5, "next": null, "previous": null, "results": [ { "id": 5, "slug": "flashdisk-robot-16gb", "sku": "dsadsa232232", "name": "Flashdisk Robot 16Gb", "description": "Ini adalah flashdisk", "weight": 6, "price": 30000, "stock": 0, "datetime_added": "2022-03-13T11:28:25.575695Z", "images": [ { "id": 1, "image": "http://127.0.0.1:8000/products/PhotoRoom-20211115_151817.png" } ], "brand": { "id": 1, "slug": "lg", "name": "LG", "image": null }, "category": { "id": 1, "slug": "electronic", "name": "Electronic", "image": null } } ] }

Mi código en React:

 useEffect(() =>{ axios.get(`http://127.0.0.1:8000/data/products/?format=json`).then(res => { const products = Object.values(res.data); var filteredCategory = products[3].filter((product) => product.category.slug === categoryslug) setProductList(filteredCategory) }) }, []); console.log(productList) return ( <> <Row> {productList && productList.map(product =>{ const {id, name, price, category,images, slug} = product; return( <Col lg={3} key={id} className="d-flex"> <Link className='card-product d-flex' to={`/product/${category.slug}/${slug}`}> <Card className="flex-fill productlist"> <Card.Img variant="top" src={images.image}/> </Card> </Link> </Col> ) })} </Row> </> )
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

images es una matriz de objetos:

 "images": [ { "id": 1, "image": "http://127.0.0.1:8000/products/PhotoRoom-20211115_151817.png" } ],

así que tienes que hacer images[0].image para que funcione.

 <Card.Img variant="top" src={images[0].image}/>
about 4 years ago · Juan Pablo Isaza Report

0

<Row> {productList && productList.map(product =>{ const {id, name, price, category,images, slug} = product; return( <Col lg={3} key={id} className="d-flex"> <Link className='card-product d-flex' to={`/product/${category.slug}/${slug}`}> <Card className="flex-fill productlist"> { images.map((val,index)=><Card.Img key={index} variant="top" src={val.image}/> } </Card> </Link> </Col> ) })} </Row>
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!