5
for(var i=0; i< numTotalPerguntasDig; i++){
strInterface +=
"<ul>"+
"<li class=\"col-md-2 \">"+
" <button type=\"button\" class=\"btn btn-danger btn-info-bloco form-control\">"+
" <span class=\"glyphicon glyphicon-plus-sign\" aria-hidden=\"true\"></span>" +
" <span class=\"texto-btn\">/span>"+
" </button>"+
"</li>"+*/
"<li class=\"col-md-2 \">"+"<input type='text' class='info-1 form-control' style='width: 100%' value='"+arraySeq[i]+"'/>"+"</li>"+
"<li class=\"col-md-6 \">"+"<input type='text' class='info-2 form-control' placeholder='Digite'/>"+"</li>"+
"<li class=\"col-md-2 \">"+
" <select class='info-3 form-control'>"+
" <option value='1'>1</option>"+
" </select>"+
"</li>"+
"<li class=\"col-md-2\">"+
"<button class='btnadd btn btn-danger btn-sm form-control' value='x'><span class='glyphicon glyphicon-remove' aria-hidden='true'></span> </button>"+
"</li>"+
"</ul>";
menu.append(strInterface);
}
append
or createElement
?
What is the best or most visual way to understand the code in a future maintenance?
Look, they’re both legible, the
createElement
will require a few more lines, but nothing problematic, in any case the biggest problem above is this concatenation of strings, in this case the use of a Template Engine will make your code much cleaner.– Tobias Mesquita
do you have any indication of template engine? angular.js can be used as a template engine?
– Denali
Denali, I posted an example with Handlebars, the advantage of it is independent of jQuery, so it can be used with whatever library. you can also use the Mustache, Jsrender.
– Tobias Mesquita
Denali, I believe it is possible, but I believe that the Angularjs template engine is quite dependent on its structure, using it stand-alone can be quite complicated, so if you’re using Angularjs, use the Angularjs Template Engine, or choose another of your preference,
– Tobias Mesquita