标记规范内的Jadevariables渲染

我有一个像这样的Jade页面:

table th Site Name th Deadline th Delete Transaction - if (transactions != null) each item in transactions tr td= item.item_name td span(id='countdown' + item.timeout + ')= item.timeout td span(style='cursor: pointer;', onclick='deleteTransaction("=item.uniqueId")')= "X" button(id='confirmButton', onclick='confirm();')Confirm 

正如你可以看到在span属性中,我尝试以两种不同的方式放置一个局部variables,它不起作用。 关于第一种方法,我收到一个token ILLEGAL错误,而第二个简单写在我的JavaScript像deleteTransaction("=item.uniqueId"); 。 我知道答案是非常愚蠢的,但一次又一次的Jade doc(即使有所改进)也不能帮助我。

谢谢

引用文档 :

假设我们有用户local { id: 12, name: 'tobi' }并且我们希望创build一个锚点标签, href指向“/ user / 12”,我们可以使用常规的javascript连接:

 a(href='/user/' + user.id)= user.name 

人机工程学:

 span(id='countdown' + item.timeout)= item.timeout // ... span(style='cursor: pointer;', onclick='deleteTransaction("' + item.uniqueId + '")')= "X" 

再次引用:

或者我们可以使用玉的插值,我补充说,因为每个人使用Ruby或CoffeeScript似乎认为这是合法的JS ..:

 a(href='/user/#{user.id}')= user.name 

所以:

 span(style='cursor: pointer;', onclick='deleteTransaction("#{item.uniqueId}")')= "X" 

作为一个常用的技巧,你会在你的编程生活中使用每一天:平衡你的报价。 就像括号和圆括号一样,每个引号都必须打开一个新的引号或closures一个已经打开的引号(同一种types,即双引号紧密的双引号,单引号紧密的单引号)。 借用你的代码:

 span(id='countdown' + item.timeout + ')= item.timeout // ^ // | // What's this guy doing? ---------+ 

即使Jade是一种模板语言,也许不是一种“真正的”编程语言,就像HTML(也不是一种编程语言)一样,这个规则将很好地为您服务。