append with jquery

1

I have a table that opens in a popup to search for material from a material requisition register, on the page (other than the pop up) has another table that when I add a material that was selected in pop up it copies the information from the selected material in the popup table to the page table. The problem is that when I add a material for example: steel, it copies the data from the steel all ok, but if I do a new search, example: concrete, when I add the concrete, instead of doing the append it overwrites the steel, if I add two materials from the same search, there it append correctly.

//Pesquisa os materiais
    function Pesquisar() {
        $('.corpoTbl').remove();
        $.ajax({
            url: "/Sip/RCM/ListarMateriais",
            type: "POST",
            data: { nome: $('#Pesquisar').val() },
            datatype: 'json',
            success: function (data) {
                $.each(data, function (I, item) {
                    $('#tbl').append("<tr class=\"corpoTbl\"> <td class=\"ids\">" + item.ID + "</td><td id=\"nome\">" + item.Nome + "</td><td id=\"unidade\"><center>" + item.Unidade +
                        "</center></td><td> <center><input class=\"qtda\" type=\"text\" value=\"0\" style=\"width: 50px;\" /></center> </td><td> <center><img class=\"icon-plus\" src=\"/Sip/Content/Imagens/add.png\" /></center> </td></tr>")
                })
            }
        });
    }

    //adiciona o item na tabela de listagem
    $('#telaMaterial').on('click', '.icon-plus', function (event) {
        var $botao = $(event.target);
        var $tr = $botao.closest('tr');
        var $qtda = $tr.find('.qtda').val();
        var $id = $tr.find('.ids').text();
        if ($qtda > 0 && $qtda != "") {
            $.ajax({
                url: "/Sip/RCM/AddCarrinho",
                type: "POST",
                data: { "qtda": $qtda, "id": $id },
                success: function (data) {
                    alert("Material Adicionado!");
                    $('#tabelaMaterial').append("<tr class=\"corpoTbl\"> <td class=\"idMat\">" + $id + "</td><td>" + $tr.find('#nome').text() + "</td><td><center>" + $tr.find('#unidade').text() +
                    "</center></td><td class=\"qtd\"><center>" + $qtda + "<center></td><td id=\"excluir\"> <center><img class=\"icon-remove\" src=\"/Sip/Content/Imagens/cancel.png\" /></center> </td></tr>")
                }
            })
        }
    })
    
asked by anonymous 11.06.2015 / 22:30

1 answer

1

When you call function Pesquisar() the first line is

$('.corpoTbl').remove();

That ends up removing all <tr class=\"corpoTbl\"> that you added earlier, I believe removing this line will work correctly. :)

    
11.06.2015 / 22:35