I have these two functions in JS , I am using jQuery and I am using the browser DB . The thing is that in the second function it does not bring me the objects because it says that result.rows.nombre(i)
it is not a function. On the other hand, in the first function ( cargaDatos ) it does work well for me. Just before I get the error with console.log
I realize that it does bring me the object and it does have a size and everything but apparently I can't access its properties to unstructure it.
function cargarDatos(){
$("#listaProductos").children().remove();
db.transaction(function(transaction){
var sql="SELECT * FROM productos ORDER BY id ASC";
transaction.executeSql(sql, undefined, function(transaction, result){
console.log(result.rows.item)
if(result.rows.item){
$("#listaProductos").append('<tr><th>Código</th><th>Producto</th><th>Cantidad</th><th>Precio</th><th></th><th></th></tr>')
for(var i=0; i<result.rows.length; i++){
var row=result.rows.item(i);
var item=row.item;
var cantidad=row.cantidad;
var id=row.id;
var precio=row.precio;
$("#listaProductos").append('<tr id="fila'+id+'" class="Reg_A'+id+'"> <td><span class="miId">A'+
id+'</span></td><td><span>'+
item+'</span></td><td><span>'+
cantidad+'</span></td><td><span>'+
precio+' USD$ </span></td><td><button type="button" id="A'+
id+'" onclick="eliminarRegistro()"><i class="fas fa-backspace"></button></i></td></tr>');
}
}else{
$("#listaProductos").append('<tr><td colspan="5" align="center">No existen los productos.</td></tr>');
}
}, function(transaction, err){
alert('Oh no, algo salió mal :c '+ err.message);
}
)
})
}
And this one, which is the same, is the one that doesn't work for me, it doesn't enter if
because it says it result.rows.nombre
is undefined
, but if I print result.rows
it does show me the object (see the last image):
function cargarFacturas(){
$("#listaFacturas").children().remove();
db.transaction(function(transaction){
var sql="SELECT * FROM facturas ORDER BY id ASC";
transaction.executeSql(sql, undefined, function(transaction, result){
console.log(result.rows.nombre)
if(result.rows.nombre){
console.log(result.rows.length)
$("#listaFacturas").append('<tr><th>#</th><th>Cliente</th><th>Total</th><th>Fecha</th><th>Estado</th><th>Tipo de pago</th><th></th></tr>')
for(var i=0; i<result.rows.length; i++){
var row=result.rows.nombre(i);
alert('itwork')
var item=row.nombre;
var cantidad=row.total;
var id=row.id;
var fecha=row.fecha;
var estado=row.estado;
var tpago=row.tpago;
$("#listaFacturas").append('<tr id="fila'+id+'" class="Reg_F'+id+'"> <td><span class="miId2">F'+
id+'</span></td><td><span>'+
item+'</span></td><td><span>'+
cantidad+'USD$ </span></td><td><span>'+
fecha+' </span></td><td><span>'+
estado+' </span></td><td><span>'+
tpago+' </span></td><td><button type="button" id="F'+
id+'" onclick="eliminarFacturas()"><i class="fas fa-shopping-cart">Pagar</i></button></i></td></tr>');
}
}else{
$("#listaFacturas").append('<tr><td colspan="5" align="center">No existen los productos.</td></tr>');
}
}, function(transaction, err){
alert('Oh no, algo salió mal2 :c '+ err.message);
}
)
})
}