I’m working on a PhoneGap app and I have this piece of code in a loop
htmlR += "html code here";
tx.executeSql('SELECT Question,Grp from KnowSelf where Dimension = "'+result.Dimension+'"', [], function(tx,resultR){
var leng = resultR.rows.length;
for(var i = 0; i < leng; i++){
var resultsR = resultR.rows.item(i);
htmlR += '<li class="catsli">'+resultsR.Question+'</li>';
htmlR += '<li class="line"><img class="line" src="iPhone3/Line.png" alt="line"/></li>';
}
},errorCB);
htmlR += "continue html code here";
My problem is, inside the tx.executeSql(.... htmlR += li tags
is not adding to the outer htmlR.
I suspect that
executeSQLdoesn’t call the callback immediately, but rather asynchronously, and so you don’t see the results immediately. If so, the correct way to handle it is to do all of your processing that relies on the results from within the callback, rather than after callingexecuteSQL. E.g., change:to