为我的应用程序使用Jade + Express + Node.js + Mongoose + MongoDB,但我遇到的这个问题很可能出现在Jade中:
我有一些代码如下,按标题,作者
打印帖子列表div#articles
-each post in records
div.article
#{post.title} was written by #{post.author}
<a href ="#{post.title}"> Link to Article </a>
现在我想要写入Jade而不是HTML的链接,但是当我用
替换该行时a(href='#{post.title}')
它链接到/#{post.title}而不是变量名称,例如/ newpost1。这样做
a(href=#{post.title})
返回错误。我确定这是一个语法问题,但我在GitHub文档中找不到解决方案
答案 0 :(得分:18)
非常确定你可以做到:
a(href=post.title)
答案 1 :(得分:5)
玉:
- var records = [ { title: 'one', author: 'one' }, { title: 'two', author: 'two' } ];
div#articles
-each post in records
div.article
| #{post.title} was written by #{post.author}
a(href =post.title) Link to Article
HTML:
<div id="articles">
<div class="article">one was written by one<a href="one">Link to Article</a></div>
<div class="article">two was written by two<a href="two">Link to Article</a></div>
</div>