0
I have this JSON file:
var identificacao = [
{
"nome": "João Silva",
"cpf": "444.111.777-00",
"rg": "44.66.55.00-1",
"nascimento": "28/06/1994",
"endereco": [{
"rua": "Av. Marechal Tito",
"numero": 155,
"bairro": "Jardim do Vale",
"cep": "08108-145",
"cidade": "São Paulo",
"estado": "SP",
},
],
"contato":[{
"telefone": "2222-2222",
"celular": "92222-2222",
"email": "[email protected]"
},
],
"renda": "5.000",
"foto": "joao_silva.jpg",
"conta":[{
"banco": "Bradesco",
"agencia": "05",
"numero_da_conta": "0102-1"
},]
},
which contains 5 items, but in my html table the only one that appears is this first item.
In my javascript I used this code:
<script>
$(function(){
x = identificacao.length;
for (var i = 0; i < x; i++) {
var saida = "";
saida += "<tr>";
saida += "<td>" + identificacao[i].nome+ "</td>";
saida += "<td>" + identificacao[i].cpf + "</td>";
saida += "<td>" + identificacao[i].rg + "</td>";
saida += "<td>" + identificacao[i].nascimento + "</td>";
for(j=0; j< identificacao[i].endereco.length;j++){
saida += "<td>" + identificacao[i].endereco[j].rua + "</td>";
saida += "<td>" + identificacao[i].endereco[j].numero + "</td>";
saida += "<td>" + identificacao[i].endereco[j].cep + "</td>";
saida += "<td>" + identificacao[i].endereco[j].bairro + "</td>";
saida += "<td>" + identificacao[i].endereco[j].cidade + "</td>";
saida += "<td>" + identificacao[i].endereco[j].estado + "</td>";
}
for(k=0; k< identificacao[i].contato.length;k++){
saida += "<td>" + identificacao[i].contato[k].telefone + "</td>";
saida += "<td>" + identificacao[i].contato[k].celular + "</td>";
saida += "<td>" + identificacao[i].contato[k].email + "</td>";
}
saida += "<td>" + identificacao[i].renda + "</td>";
saida += "<td>" + identificacao[i].foto + "</td>";
for(n=0; n< identificacao[i].conta.length;n++){
saida += "<td>" + identificacao[i].conta[n].banco + "</td>";
saida += "<td>" + identificacao[i].conta[n].agencia + "</td>";
saida += "<td>" + identificacao[i].conta[n].numero_da_conta + "</td>";
}
saida += "</tr>";
$("#tbody").append(saida);
$("#tabela").dataTable();
}
});
</script>
I would like help to know what mistake I am making, and how can I make all my items appear on the table.
You’ve tried it with $.each.?
– Leo Letto