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

136
Views
Cómo extraer el nombre de un par de nombre/valor JSON y agregarlo a un campo de texto

Tengo JSON que se ve así:

 { "Id": 1, "Title": "Data about John Doe", "Comments": "Some text goes here", "UpdatedBy": "John Doe", "UpdateDate": "Apr 14 2022 12:00AM" }

Quiero asignar este JSON a MUI TextFields con los nombres de los pares de nombre/valor como etiquetas de TextField y los valores como valores de TextField. También necesito poder editar los valores.

Esta es mi matriz de datos:

 const [singleSizing, setSingleSizing] = useState(""); const fetchSizingData = async (intake_id, sizing_id) => { setSingleSizing( await fetch(`/api/fiscalyears/FY2023/intakes/${params.id}/details/questions`).then((response) => response.json() ) ); };

Estos son los campos de texto que estoy usando:

 <TextField value={} label={} />
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Suponiendo que singleSizing es un objeto JSON. Si no, mapea primero:

Puede usar Object.entries para extraer el par clave/valor del objeto y luego .map() sobre las entradas para crear los componentes.

 // ... return Object.entries(singleSizing).map(sizingEntry => { const [label, value] = sizingEntry; // eg ['Title', 'Data about John Doe'] return <TextField label={label} value={value} /> }); // ...

Para editar los valores, busque en los componentes de un formulario MUI u otra biblioteca de formularios y considere cambiar la forma del estado para facilitar las actualizaciones.

about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar .map y Object.keys

 { Object.key(singleSizing).map(key => ( <TextField value = { obj[key] } label = { key } /> )) }
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!