尝试从mongo中自动选择jade数据中的多个选项

时间:2016-08-05 03:01:02

标签: node.js html5 mongodb pug

'数据'代表当前选定的宠物 '宠物'代表MongoDB中的所有宠物 试图选择之前被选为冲突的宠物

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}

有点不见了

    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

女巫工作得很好我错过了什么可以自动选择多个选项?

1 个答案:

答案 0 :(得分: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}

      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

最终都为我工作了。