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

207
Visualizações
How to make a dropdown of the data receive from ajax response as array of objects

I want to make a dropdown in my table which is populated with the dynamic data coming from ajax response and append to the table. My postman collection looks like this.

{
    "createdDate": "2022-04-06T11:42:37.360Z",
    "enabled": true,
    "_id": "62502b868daa3b1cdbdc98e8",
    "CNIC": "40740c7d9f3a11d93e76af7f2f60887a",
    "employeeID": "LE44337",
    "fName": "HUSNAIN",
    "company": "6249fdf91399dc7a14173dcd",
    "fatherName": "husnain",
    "motherName": "momutaz",
    "spouse": "no spouse",
    "children": [{
        "_id": "62502b868daa3b1cdbdc98e9",
        "name": "hunsian",
        "age": 23232
    }, {
        "_id": "62502b868daa3b1cdbdc98ea",
        "name": "hunsian",
        "age": 12121
    }, {
        "_id": "62502b868daa3b1cdbdc98eb",
        "name": "momin",
        "age": 2323
    }
}

And below is my ajax response code in which I am appending the data into table.

success : function(response){
                        
    var trHTML = '';
    $.each(response.doc, function (i, item) {
                        
        trHTML += '<tr><td>' + item.fName + '</td><td>' + item.CNIC + '</td><td>' + item.spouse + '</td><td>'+ item.fatherName + '</td><td>' + item.motherName +'</td><td>'+ item.employeeID +'</td><td>' + item.children.map(({name, age}) => `Name: ${name} Age: ${age}`).join('  ||  ') +'</td></tr>';
    });
    $('#records_table').append(trHTML);
}

The itme.children name , age I want to make a dropdown of it into table so it looks good.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you mean a dropdown like a select menú, this should do the job

trHTML += `... <td>
    <select>
        <option selected disabled>Click me</option>` + 
        item.children.map(({name + age}) => `<option>Name: ${name}, Age: ${age}</option>`).join('') +
    `</select></td>`;
over 4 years ago · Santiago Trujillo 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