-1
By clicking the button, run this code down
It was to generate only one position of the array. In this case it is generated 3 positions, as if there had been 3 tests
$(document).on('click','#btnSegundaEtapa',function () {
var arrayObjCat1 = [];
$(".form-group").find('*').each(function(){
var id = $(this).attr("id");
if($(this).is(':checked')){
if ( $("input[type='radio'][name='Licenciamentodeusuários']").is(':checked') ) {
className = $("#"+id).data('class-name');
vlrUnitario = $("."+className).text();
vlrUnitario = vlrUnitario.replace("$","");
vlrUnitario = parseFloat(vlrUnitario.replace(',','.'));
arrayObjCat1.push({part_number:$('#'+id).data('part-number'), nome_item:$('#'+id).data('nome-item'),qtde:$('#'+id).val(),preco_unitario:vlrUnitario});
console.log(arrayObjCat1);
}
}
})
});
Consider explaining your problem better
– Victor Eyer
I pressed to publish unintentionally, look if it became clearer
– gabrielfalieri
Gabriel, what is the question or what is not working as you want?
– Sergio
I want this data to be executed only once and not 3 times
– gabrielfalieri
You are running
console.log
within the functioneach
, this means it will print on the console each time it passes the loop. Try to put the console out of the loop that will print only once.– Pedro Camara Junior
You have
$(".form-group").find('*').each(
this will make the code run over and over again...– Sergio
But it generates an array of 3 positions, which I don’t want
– gabrielfalieri