I'm trying to setup some checkboxes with data from a DB. Basically there are menu options which are stored in a database table and then there is a field in my users table which contains a comma separated string with the id's of the menu option that the user can access.
What I need to do is loop the menu options, the for every menu option loop through the comma separated string and if a match is found, set the checkbox checked and exit the loop.
- var arruserperms = userperms.split(',')
div(class="row")
for p in perms
for up in arruserperms
if (p.mid == up)
- checked = 'checked'
break
div(class="col-md-3 text-left")
input(type="checkbox" checked=(checked) class="perms" id="menu_#{p.mid}")
label(for="menu_#{p.mid}") #{p.mdescription}
perms
is an object from a route which fetches data from a postgresql database and arruserperms
is the field from the login table which has been converted to array in the jade file.
The checkboxes are displaying properly. The only issue is that I cannot get them checked.
Aucun commentaire:
Enregistrer un commentaire