3
I have a JSON I’m using to generate an HTML in a app Cordova as follows:
function gerarLista(lista) {
strHtml = "";
for(item in lista) {
strHtml += '<div class="item">';
strHtml += '<div class="descricao">' + lista[item].descricao + '</div>';
strHtml += '<div class="imagem">';
strHtml += '<img src="' + lista[item].imagem + '" />';
strHtml += '</div>';
strHtml += '<div class="valor">' + lista[item].valor + '</div>';
strHtml += '</div>';
}
$("#produtos").html(strHtml);
}
To generate a small list is quiet, but when you have a larger amount of products the interface of a locked when I call this function, I see this because when this function is called already has a css animation running.
I was wondering if you have any better way (in the performance question) to generate this html? From what I understood the for
run time so there’s some way to run it asynchronously or whatever, so there’s no locking?
I believe that using https://handlebarsjs.com you can do something more interesting. Or try something with Interpolation string in javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
– SylvioT
You can try to follow the modern frameworks approach and update only what you have changed by not touching the products that remain the same. Certainly implies more logic.
– Isac
@Isac the problem is the first time I will create these elements in which happens the
lag
– Bruno Romualdo