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

135
Views
Cómo formatear la respuesta para completar la selección en reaccionar nativo

Estoy tratando de formatear los elementos que vinieron en el campo Terminales a una matriz de {clave, etiqueta} para completar un menú desplegable

 Object { "Status": "SUCCESS", "Terminals": Object { "0": Object { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", }, "1": Object { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", }, "name": "", "term_id": "", }, "TotalCount": 1 }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Tiene un recuento total en su respuesta, por lo que, en función de ese recuento total, lea cada dato del objeto y páselo a la variable de opciones. Un bucle for simple puede resolver este problema.

revisa mi codigo

 let response = { "Status": "SUCCESS", "Terminals": { "0": { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", }, "1": { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", }, "name": "", "term_id": "", }, "TotalCount": 2 } let options = []; for(let i=0; i<response.TotalCount; i++) { options.push({key:response.Terminals[i].term_id, label: response.Terminals[i].name}) } console.log(options)

about 4 years ago · Juan Pablo Isaza Report

0

Usando Object.values()

 const data = { "Status": "SUCCESS", "Terminals": { "0": { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", }, "1": { "name": "GENESIS- DEMO Terminal", "term_id": "GENESIS", } }, "TotalCount": 1 }; const dropDownArray = Object.values(data.Terminals).map(({ name: label, term_id: key }) => ({ key, label })); console.log(dropDownArray);

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!