Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
How to extract Name from a JSON Name/Value pair and append to a TextField

I have JSON which looks like this:

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

I want to map this JSON to MUI TextFields with the names of the name/value pairs as the TextField labels, and the values as the TextField values. I also need to be able to edit the values.

This is my array of data:

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()
            )
  );
};

These are the Text Fields I am using:

<TextField
  value={}
  label={}
/>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Assuming singleSizing is one JSON object. If not, map over first:

You can use Object.entries to extract the key/value pair from the object and then .map() over the entries to create the components.

// ...

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

// ...

To edit the values, look into a MUI form components or another form library and consider changing the shape of the state to make updates easier.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use .map & Object.keys

 {
     
      
        Object.key(singleSizing).map(key => ( 
          <TextField 
              value = {
                obj[key]
              }
              label = {
                key
              }
            />
        ))
      
 }


about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda