2016-08-05 31 views
0

mehrere Optionen in Jade Daten von Mongo Der Versuch, ‚Daten‘ stellt die aktuelle ausgewählte Haustier ‚Haustiere‘ alle Haustiere in MongoDB stellt versuchen, die Tiere zu wählen, die zuvor als Konflikte ausgewählt wurdenzu auto wählen

label.col-sm-3.control-label(for='petConflicts') Pet Conflicts 
.col-sm-7 
select.form-control(name='petConflicts', multiple=true) 
    each pet, index in pets 
    option(value=pet._id, selected=data.petConflicts[index]===pet._id) #{pet.name} 

wurde abgehend irgendwie

label.radio.col-sm-3 
     input(type='radio', name='gender', checked=data.gender=='male', value='male', data-toggle='radio') 
     span Male 
    label.radio.col-sm-3 
     input(type='radio', name='gender', checked=data.gender=='female', value='female', data-toggle='radio') 
     span Female 

Hexe funktioniert großartig ich etwas fehlt bin, ist es möglich, automatisch auf mehrere Optionen auswählen?

Antwort

0
  if data.petConflicts.indexOf(pet._id) > -1 
      option(value=pet._id, selected=true) #{pet.name} 
      else 
      option(value=pet._id, selected=false) #{pet.name} 

oder

 select.form-control(name='plan') 
     option(value=1, selected=data.plan===1) Once a week 
     option(value=2, selected=data.plan===2) Twice a week 
     option(value=3, selected=data.plan===3) Three times a week 
     option(value=4, selected=data.plan===4) Four times a week 
     option(value=5, selected=data.plan===5) Five times a week 
     option(value=6, selected=data.plan===6) Six times a week 
     option(value=7, selected=data.plan===7) Every day 

beide endete für mich arbeiten.