gpt4 book ai didi

node.js - Jade 变量渲染内标签规范

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:45 25 4
gpt4 key购买 nike

我有一个像这样的 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 属性中看到的那样,我尝试以两种不同的方式放置局部变量,但它不起作用。关于第一种方式,我收到一个 token ILLEGAL 错误,而第二种方式只是在我的 JavaScript 中写入类似 deleteTransaction("=item.uniqueId"); 的内容。我知道答案确实很愚蠢,但一次又一次 Jade 文档(即使它有所改进)对我没有帮助。

谢谢

最佳答案

引用the docs :

Suppose we have the user local { id: 12, name: 'tobi' } and we wish to create an anchor tag with href pointing to "/user/12" we could use regular javascript concatenation:

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

因此:

span(id='countdown' + item.timeout)= item.timeout

// ...

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

再次引用:

or we could use jade's interpolation, which I added because everyone using Ruby or CoffeeScript seems to think this is legal js..:

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

所以:

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

作为您在编程生活中每天都会用到的一般提示:平衡您的引用。就像方括号和圆括号一样,每个引号必须打开一个新引号或关闭一个已经打开的引号(相同类型,即双引号关闭双引号,单引号关闭单引号)。借用您的代码:

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

尽管 Jade 是一种模板语言,也许不是“真正的”编程语言,但这条规则,就像 HTML(也不是编程语言)一样,将为您提供良好的服务。

关于node.js - Jade 变量渲染内标签规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9517605/

25 4 0
文章推荐: html - 使用 :checked css pseudo class with no javascript 使同级
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com