0
I have a file with a function that takes all records from a table, as below.
window.lerTabelaListas=function()
{
lista=new Array();
db.transaction(function (tx)
{
tx.executeSql('SELECT * FROM listas',[],function (tx, results)
{
var len= results.rows.length, i;
for(i=0; i<len; i++)
{
var nome=results.rows.item(i).nome
var id=results.rows.item(i).idLista
lista.push(nome,id)
}
});
});
return lista;
}
When I call this function I can’t get any feedback, I can’t, for example, make a foreach
to extract these values. By log console, but he returns:
Array(32)
0
:
"lista de: 2/3/2018"
1
:
1
2
:
"lista básica "
I need some help, guys, since I’m a beginner in Javascript.
The
executeSql
works asynchronously, it does not "wait" the result to then return the value.– Valdeir Psr
Let me see if I understand, excecute sql works independently,? What/how could I do then,
– Mr.Bobot
Basically.. What you can do is use one Promise or a function of
callback
.– Valdeir Psr
Thanks, I’ll read about
– Mr.Bobot