How to mount a list with checkbox starting from an array?

-1

Talk to people, blz? I'm a beginner in web programming and I'm doing a hybrid application for mobile devices, I'd like to know how I can populate a list by bringing the name of an object and its id inside an array into a js function using jquery. Here is the code:

 <div class="list-group" id="itensAmigoConta" style="margin-top: 5%">
 </div>
    
asked by anonymous 29.06.2018 / 22:25

1 answer

0

Oops, what's up? You have to make a for going through your array and so go mount the html inside the div with .append, inserting the field taken by the array and its index, also adding an input with the type checkbox and putting the index as its id, as follows:

function exemploLista() {

$("#itensAmigoConta").html("");

for(i in seuArray){
    $("#itensAmigoConta").append("<li >"+
    "<label>"+seuArray[i].campo+""+
    "<input type='checkbox' id='"+i+"'>"+
    "</label></li>");
}
    
29.06.2018 / 22:26