javascript - Jade 选择字段填充数据

标签 javascript node.js pug

有没有更好的方法来填充基于 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/

相关文章:

javascript - 如何查找 innerHtml(text) 超出容器元素宽度

node.js - 如何使用 node.js 将直通上传到 Heroku 上的 s3?

node.js - 从命令行运行哈巴狗

html - 以 HTML 格式语法包含另一个 Jade 文件

javascript - Mocha 测试后关闭服务器,但数据仍然存在

javascript - Cloud Functions for Firebase 超时

node.js - 断言失败(node.js): what does Operator parameter mean?

javascript - Jade 逃逸问题?

javascript - 如何将spyMargin与ng-scrollable一起使用

javascript - D3 库可以与 Electron(Atom shell)一起使用吗?