Error in listing interface

Asked

Viewed 17 times

0

I’m doing a college exercise, and when I click the resposable button for listing, my table is redone whole, so I lose the names that should be on the first line, which are:

-Codigo -Limite do Prazo -Nome do Usuario -Categoria -Comentarios

However, the first line is already replaced by the bank’s information


<div class="col-md-12">
    <h3>Listagem</h3>
      <section>
        <button id="btListar" class="btn btn-info">Listar Atendimentos</button>
         <br />
         <br />
         <table class="table" id="tabelaLista" border="3">
            <thead class="thead-dark">
               <tr>
                  <td>Codigo</td>
                  <td>Limite do Prazo</td>
                  <td>Nome do Usuario</td>
                  <td>Categoria</td>
                  <td>Comentarios</td>
               </tr>
           </thead>
          </table>
  </section>
</div>
 var auxHTML = '';
 listaObjetos = JSON.parse(resposta);
 var total = listaObjetos.length;
 for (var i = 0; i < total; i++) {
    auxHTML += '<tr>' + 
            '<td>' + listaObjetos[i].code + '</td>' +
            '<td>' + listaObjetos[i].deadline + '</td>' +
            '<td>' + listaObjetos[i].userName + '</td>' +
            '<td>' + listaObjetos[i].category + '</td>' +
            '<td>' + listaObjetos[i].comments + '</td>' +
            '</tr>';
              }
  $('#tabelaLista').html(auxHTML);

  • @user140828 It worked perfectly! I would like to add the correction so I can mark it?

1 answer

1


The method .html(meuHTML) jQuery overwrite all the HTML of the found object, to concatenate more HTML with the existing one, you can use .append(meuHTML) to add this HTML at the end of the existing one, or .prepend(meuHTML) to add HTML at the beginning of the existing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.