I have a problem in my method. elenco_prodotti
must wait the method sincro.query
to proceed to add the final outputs, but now I see only the empty divs, because it needs to be synchronous.
Please, help me!
this.elenco_prodotti = function (callBack) {
var output = '';
for (var c = 1; c < 5; c++ /*categoria*/)
{
for (var p = 1; p < 5; p++/*pagina*/)
{
output += "<div class='pag_" + p + " cat_" + c + "'>";
var sql = 'SELECT cat_varianti,colore_tasto,id,descrizione,prezzo_1 FROM prodotti WHERE categoria="' + c + '" AND pagina="' + p + '"';
output += '<div class="bs-docs-section btn_' + comanda.dispositivo + ' "> \n\
<div class="bs-glyphicons"> \n\
<ul class="bs-glyphicons-list">';
for (var y = 1; y <= 6; y++) {
for (var x = 1; x <= 8; x++) {
var posizione_attuale = y + "-" + x;
var testo_query = sql + ' AND posizione="' + posizione_attuale + '" LIMIT 1;';
comanda.sincro.query(testo_query, function (prodotto)
{
if (prodotto[0] && prodotto[0]['descrizione'].length > 0)
{
prodotto = prodotto[0];
prodotto['descrizione'] = prodotto['descrizione'].replace("'", " ");
switch (comanda.dispositivo) {
case "COMANDA":
if (prodotto['descrizione']) {
output += '<li style="background-color:' + prodotto['colore_tasto'] + '" onClick="aggiungi_articolo(\'' + prodotto['id'] + '\',\'' + prodotto['descrizione'] + '\',\'' + prodotto['prezzo_1'] + '€\',\'null\',$(\'#quantita_articolo\').val(),\'null\',\'' + prodotto['cat_varianti'] + '\')"> \n\
<span class="glyphicon-class">' + prodotto['descrizione'] + '<br/>€ ' + prodotto['prezzo_1'] + '</span> \n\
</li>';
} else {
output += '<li style="display:table;"> \n\
<span class="glyphicon" aria-hidden="true"></span> \n\
<span class="glyphicon-class"></span> \n\
</li>';
}
break;
case "LAYOUT TASTI":
output += '<li ';
if (prodotto['colore_tasto']) {
output += 'style="background-color:' + prodotto['colore_tasto'] + '"';
}
output += ' onClick="modifica_articolo(\'' + c + '\',\'' + posizione_attuale + '\',\'' + prodotto['colore_tasto'] + '\');"> \n\
<span class="glyphicon-class">' + prodotto['descrizione'] + '</span> \n\
</li>';
break;
default:
break;
}
output += '</ul></div></div>';
}
else
{
prodotto = null;
}
});
}
}
output += '</div>';
}
}
callBack(output);
};