简体   繁体   中英

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. Use this:

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

Changes:

  • use each...in
  • use tag = variable for interpolation when possible, not #{variable}
  • Jade doesn't have brackets, it's indentation based
  • if doesn't need parens

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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