How to build a checkbox list from an array?

Asked

Viewed 96 times

-1

You guys talking, Blz? I am a beginner in web programming and am doing a hybrid application for mobile devices, I would like to know how to fill a list with the name of an object and its id inside an array in a js function using jquery. Follows the code:

 <div class="list-group" id="itensAmigoConta" style="margin-top: 5%">
 </div>
  • Beware of bad codes. The answer you accepted has problems.

1 answer

0


Oops, and ae, beauty? You have to do one by scrolling through your array and so go riding the html inside the div com . append, inserting the field caught by the array and its index, adding an input with the type checkbox and placing 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>");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.