答案 0 :(得分:2)
要指定所选选项,需要将selected
属性添加到option
元素:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select
假设blob.kind
属性是值字符串,您可以为select
和option
元素编写Jade,如下所示:
-
var options = [
{value: 'option1', text: 'Option 1'},
{value: 'option2', text: 'Option 2'},
{value: 'option3', text: 'Option 3'},
{value: 'option4', text: 'Option 4'}
];
select
each obj in options
if (blob.kind === obj.value)
option(value= obj.value, selected)= obj.text
else
option(value= obj.value)= obj.text
为了将来参考,Jade已经renamed to Pug。
答案 1 :(得分:0)
我曾经这样做过:
select
each obj in options
option(value= obj.value, selected=blob.kind === obj.value ? true : false)=
obj.text
答案 2 :(得分:0)
- const stateOptions = [{value:'AL', text:'Alabama'}, ...]
select#state(name='state' required)
each option in stateOptions
if (option.value === meeting.state)
option(value=(option.value) selected) #{option.text}
else
option(value=(option.value)) #{option.text}