简体   繁体   English

玉器文件之间的javascript失败

[英]javascript between jade file failed

My below code broken 我的下面的代码坏了

span 
    a.active(href="#{code}")
    - myArr.forEach(entry){
      if(entry.code == code){
        #{entry.ItemName}  
      }
    }

My expected result is 我的预期结果是

<span><a href="John">John James</a></span>

You're mixing javascript to be executed by Jade with output code. 您正在将要由Jade执行的javascript与输出代码混合在一起。 Use this: 用这个:

span 
  a.active(href = code)
    each entry in myArr
      if entry.code == code
        = entry.ItemName

Changes: 变化:

  • use each...in 使用each...in
  • use tag = variable for interpolation when possible, not #{variable} 尽可能使用tag = variable进行插值,而不是#{variable}
  • Jade doesn't have brackets, it's indentation based Jade没有括号,它基于缩进
  • if doesn't need parens if不需要parens

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM