9

I'm using Jade templates in an edit view where I edit a user's details, and a dynamically generated radio button like so (comes from my mongodb):

li Role:
      br
      label Subscriber
      input(type="radio", name="user[role]", val="subscriber")
      br
      label Admin
      input(type="radio", name="user[role]", val="admin")
      br
      label Super Admin
      input(type="radio", name="user[role]", val="superadmin")

How do I set one to checked dynamically?

So if in my db, my role is subscriber , how do I check for that? "Normally", I would do a if(user.role == 'subscriber'){'checked'} and so on for all of the different values.

Where/how does that logic go into this bit of Jade?

4

1 回答 1

14

input(type ='radio', name=user[role], checked)

To dynamically check, see examples below:

input(type ='radio', name=user[role], checked=true)   
input(type ='radio', name=user[role], checked=false)   
input(type ='radio', name=user[role], checked=role=='user')
于 2012-05-05T18:34:55.537 回答