Good day. I generate a list of products in a table dynamically in the following way:
var productos;
$$("#productos").blur(function(e){
console.log("Mostrar resultado del producto");
var CodigoInventario = 0016;
//--- Buscar productos ---
axios.get('https://URL/AppBuscarProducto?IDPedido=${idPedido}&CodigoInventario=${CodigoInventario}',{
headers: {
Authorization: token_type + " " + access_token
}
}).then(function (response) {
console.log(response);
productos = response.data;
$("#resultadoProductos > tbody > tr").remove();
var resultadoProductos = $('#resultadoProductos');
$.each(productos, function(i){
$('<tr/>')
.append($('<td/>').addClass('label-cell').append(productos[i].Descripcion))
.append($('<td/>').addClass('label-cell').append(productos[i].PrecioSocio))
.append('<input id="descripcionProducto" value="'+productos[i].Descripcion+'" style="display:none"></input>')
.append($('<td/>').addClass('label-cell').append('<button value="'+productos[i].Codigo_Inventario+'" type="button" id="btn-agregarCarrito" class="button button-fill button-raised button-circle color-green" title="Comment"><i class="fa fa-shopping-cart"></i></button>'))
.appendTo(resultadoProductos);
});
}).catch(function (error) {
console.log(error);
myApp.hideIndicator();
});
});
and in the next function I capture the value of the data generated in the table dynamically, for now I have only been able to capture the value of the button.
var valCarrito = [];
$$("#resultadoProductos").click('#btn-agregarCarrito',function(e){
var codProducto = $(this).val(); //Aqui capturo el valor del boton btn-agregarcarrito, este si muestra los valores dinamicos, es decir no muestra siempre el mismo valor del boton, sino va cambiando segun lo que haya seleccionado.
var descProducto = $("#descripcionProducto").val(); //aca debo obtener el valor del input descripcionProducto, pero unicamente logro obtener el primer valor generado,
var cantProducto = $("#cantProducto").val();
console.log("SE AGREGA UN PRODUCTO");
console.log(codProducto);
console.log(descProducto);
valCarrito.push({
"codProducto": codProducto,
"cantProducto": cantProducto
})
console.log("DATOS DEL CARRITO:");
console.log(valCarrito);
e.preventDefault();
});