有没有更好的方法来填充基于 Jade 的选择字段,我目前正在使用这个示例。有没有更好的方法不破坏模板代码?
item值为'day'的例子。
select
repeation = [ 'no-repeat', 'day', 'week', 'month']
for item in repeation
if job.repeat == item
option(selected="true") #{item}
else
option #{item}
当项目是 ['day', 'week'] 的数组时,如何显示多个选择?
//为多个元素编辑可能的小解决方案
enginges = [ 'google', 'bing', 'yahoo', 'duckduckgo']
for engine in enginges
option(selected=job.sources.indexOf(engine) != -1) #{engine}
最佳答案
您应该能够执行以下操作:
for item in repeation
option(selected=job.repeat == item) #{item}
同样的概念应该能够应用于多项目选择下拉菜单。
关于javascript - Jade 选择字段填充数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10362959/