Ris*_*vik 19 javascript node.js pug
有没有更好的方法来填充基于Jade的选择字段,我目前正在使用此示例.有没有更好的方法来破坏模板代码?
项目值是"天"示例.
select
repeation = [ 'no-repeat', 'day', 'week', 'month']
for item in repeation
if job.repeat == item
option(selected="true") #{item}
else
option #{item}
Run Code Online (Sandbox Code Playgroud)
当项目是['day','week']的数组时,还要显示多个选项呢?
//为多个元素编辑小的可能解决方案
enginges = [ 'google', 'bing', 'yahoo', 'duckduckgo']
for engine in enginges
option(selected=job.sources.indexOf(engine) != -1) #{engine}
Run Code Online (Sandbox Code Playgroud)
Ant*_*lad 36
你应该可以这样做:
for item in repeation
option(selected=job.repeat == item) #{item}
Run Code Online (Sandbox Code Playgroud)
相同的概念应该能够应用于多项目选择下拉列表.