Cor*_*rey 12 node.js express pugjs pug
我正在玩Node和Express,我正在使用Pug(以前的Jade)模板引擎来渲染我的html.一切都工作正常,直到我开始尝试将变量注入href我的锚链接.奇怪的是,如果我改变我的Express应用程序view engine,jade那么事情就会按预期开始工作.
根据我读过的其他文章,这个问题似乎是一个插值问题,但我似乎无法找到显示如何正确解决此问题的资源或文档.
防爆.
我从roomsjson数组中提取数据,然后使用for循环遍历每个数组元素并输出每个房间的数据.使用jade以下作品.
table.table.table-striped
thead
tr
th Name
th Id
tbody
each room in rooms
tr
td(style="width: 50px;")
a(href!="/admin/rooms/delete/#{room.id}") Delete
td #{allTitleCase(room.name)}
td #{room.id}
Run Code Online (Sandbox Code Playgroud)
使用pug上述方法无法正常工作.特别是a(href='/admin/rooms/delete/#{room.id}') Delete链接无法正常工作.它不是将房间id注入到链接href中,而是输出#{room.id}作为href链接的结尾部分.
任何想法如何解决这个问题pug?
请注意,我已尝试使用以下所有pug选项,但这些选项均无效.
a(href="/admin/rooms/delete/#{room.id}") Deletea(href!="/admin/rooms/delete/#{room.id}") Deletepdo*_*926 20
更新:Pug 2.0引入了对插值处理方式的重大更改.
根据更改日志,以下任何一项都应该有效:
// to solve OP's problem, the following can be used:
a(href="/admin/rooms/delete/" + room.id) Delete
// Here are a few additional scenarios which use the new API
// for anyone stumbling across this answer in the future
- var href = "/admin/rooms/delete/" + room.id;
a(href=href)
a(href=`${href}`) // Node.js/io.js ? 1.0.0
a(href=href + '?foo=bar')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10070 次 |
| 最近记录: |