Oi, bom dia. Tenho o seguinte código, o qual utiliza um framework jqwidget (
<div id='content'> <script type="text/javascript"> $(document).ready(function () { var url = "lstprodutos.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'Produto', map: 'm\\:properties>d\\:Produto' }, ], root: "entry", record: "content", id: 'm\\:properties>d\\:CustomerID', url: url }; var dataAdapter = new $.jqx.dataAdapter(source, { async: false }); // Create a jqxInput $("#jqxInput").jqxComboBox({ source: dataAdapter, placeHolder: "Digite o nome de um produto...", displayMember: "Produto", valueMember: "Produto", width: 800, height: 30 }); $("#jqxButton").jqxButton({ height: '30px', width: '200px', }) }); var array = []; RemoveTableRow = function(handler) { var tr = $(handler).closest('tr'); tr.fadeOut(400, function(){ var index = array.indexOf('valor.value'); array.splice(index, 1); tr.remove(); var itens =1; $('#products-table tr td.cont-item').each(function() { $(this).empty().html(itens+'.'); itens++; }); }); return false; }; function insereValor() { var valor = $("#jqxInput").jqxComboBox('getSelectedItem'); if(!valor) { alert('Por favor, escolha um produto!!!'); } else if (array.indexOf(valor) < 0) { array.push(valor); // Valor adicionado var rowCount = $('#products-table tr').length - 1; var newRow = $("<tr>"); var cols = ""; cols += '<td class="cont-item">'+rowCount+'. </td>'; cols += '<td><input type="text" name="produtos[cod][]" disabled="yes" /></td>'; cols += '<td><input type="text" name="produtos[qtd][]" style="text-align: center;" /></td>'; cols += '<td><input type="text" name="produtos[und][]" style="text-align: center;" /></td>'; cols += '<td><input type="text" id="descricao" name="produtos[desc][]" value="'+valor.value+'" style="width:300px" /></td>'; cols += '<td><input type="text" name="produtos[preco][]" style="text-align: center;" /></td>'; cols += '<td class="actions">'; cols += '<input class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button" value="X" />'; cols += '</td>'; newRow.append(cols); $("#products-table").append(newRow); $("#jqxInput").jqxComboBox('clearSelection'); return false; $("#log").text(selectedItems); } else { alert('O item já foi adicionado!!!'); } // Fim valor duplicado } </script> <div id="outer"> <div id="inner"> <div id="jqxInput" class="button2"> </div> <input type="button" onclick="insereValor()" class="but but-primary but-shadow but-rc" value="Inserir item" /> </div> </div> </div> <fieldset> <table id="products-table" class="tabela-itens"> <tbody> <tr> <th>Item</th> <th>Código</th> <th>Descrição</th> <th>Preço Unitário R$</th> <th class="actions">Ações</th> </tr> </tbody> <tfoot> <tr> <td colspan="7" style="text-align: left;"> <button class="btn btn-large btn-success" onclick="AddTableRow(this)" type="button">Adicionar Item</button> </td> </tr> </tfoot> </table> </fieldset>
Ele tá pegando os valores da combobox e armazenando os valores em uma array. Quando seleciono e clico em "inserir item", ele cria uma nova linha na tabela com a descrição do produto preenchida. Até aqui, tudo ok! Porém, quando eu removo um determinando item da lista e tento adicionar novamente, ele diz que o item já existe, pois não tá removendo do array. Como fazer para excluir também do array?