Popular form (Array of objects)

0

I have the following array of objects:

WhatIhaveofthisobjectistheindex,andIwanttousethisindextopopulateaform.

Inthefunctionbelow,faseisarrayandIDistheindexoftheobject.

Butasitstands,Icanonlypopulatethefirstindex[0].

HowcanIdisplayinformationinthefieldsaccordingtothecorrectindex?

function_carrega_fase(fase,id){for(vari=0;i<fase.length;i++){$('#txt_atraso_inicial_alt').val(fase[i].atraso_inicial);$('#txt_atraso_final_alt').val(fase[i].atraso_final);$('#txt_multa_alt').val(fase[i].multa);$('#txt_juros_alt').val(fase[i].juros);$('#txt_honorario_alt').val(fase[i].honorario);}}

Ihopetheformdisplaystheinformationasbelow

    
asked by anonymous 13.11.2017 / 17:02

1 answer

1

From what I understand of your code, it is iterating through all the elements, and is overwriting the values of the fields at each iteration, is that even your proposal?

If the purpose is to get a specific index and popular your form try:

function _carrega_fase(fase, id) {
    $('#txt_atraso_inicial_alt').val(fase[id].atraso_inicial);
    $('#txt_atraso_final_alt').val(fase[id].atraso_final);
    $('#txt_multa_alt').val(fase[id].multa);
    $('#txt_juros_alt').val(fase[id].juros);
    $('#txt_honorario_alt').val(fase[id].honorario);
}
    
13.11.2017 / 19:32