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

220
Views
Mostrar matriz anidada según el valor anidado

Estoy tratando de mostrar una matriz anidada en mi pantalla (vea la matriz a continuación), la primera capa se muestra correctamente, pero cuando intento mostrar la segunda, no devuelve nada, los elementos en la matriz de la segunda capa deben ser se muestra solo si se selected=false , es por eso que decidí usar una función forEach primero.

mapa

 const items = order.order.map((item) => { const additional = item.additional.forEach((e) => { e.data.map((a) => { const id = Math.random() * Math.random() + a.id if(a.selected == false){ return( <View key={id}> <Text>{a.title}</Text> <Text>$ {a.price}</Text> </View> ) } }) }) return ( <View key={item.id}> <Text>{item.quantity}</Text> <Text>{item.title}</Text> <Text>$ {item.price.toFixed(2)}</Text> {additional} </View> ) })

matriz ARTÍCULO

 Object { "additional": Array [ Object { "data": Array [ Object { "id": 0, "price": 0, "selected": false, "title": "Hot Sauce", "type": "Sauces", }, Object { "id": 1, "price": 0, "selected": false, "title": "Medium Sauce", "type": "Sauces", }, ], "id": 1, "required": true, "title": "Sauces", }, Object { "data": Array [ Object { "id": 0, "price": 1, "selected": false, "title": "Ranch", "type": "Sides", }, Object { "id": 1, "price": 1, "selected": false, "title": "Blue Cheese", "type": "Sides", }, ], "id": 0, "required": false, "title": "Sides", }, ], "id": 0.103, "price": 6.95, "quantity": 1, "title": "Buffalo Wings", }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

import "./styles.css"; const data = { additional: [ { data: [ { id: 0, price: 0, selected: false, title: "Hot Sauce", type: "Sauces" }, { id: 1, price: 0, selected: true, title: "Medium Sauce", type: "Sauces" } ], id: 1, required: true, title: "Sauces" }, { data: [ { id: 0, price: 1, selected: true, title: "Ranch", type: "Sides" }, { id: 1, price: 1, selected: false, title: "Blue Cheese", type: "Sides" } ], id: 0, required: false, title: "Sides" } ], id: 0.103, price: 6.95, quantity: 1, title: "Buffalo Wings" }; export default function App() { return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Start editing to see some magic happen!</h2> <div className="content" key={data.id}> <div>Title: {data.title}</div> <div>Price: {data.price.toFixed(2)}</div> <div>Qty: {data.quantity}</div> <br /> <div>Additional:</div> {data.additional.map((item, index) => { return ( <div key={item.id}> {item.title}: <ul> {item.data .filter((data) => !data.selected) .map((data, dataIndex) => { return ( <li key={data.id}> <div> {data.title} - {data.type} </div> </li> ); })} </ul> </div> ); })} </div> </div> ); }

Como se mencionó anteriormente, forEach no devolvió nada. Para que pueda combinar filtro y mapa. Aquí está el entorno limitado de trabajo https://codesandbox.io/s/competent-leavitt-b2e2ec?file=/src/App.js

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!