11

在我的应用程序中使用 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 文档中找不到解决方案

4

2 回答 2

18

很确定你可以这样做:

a(href=post.title)
于 2011-04-18T02:08:30.993 回答
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>
于 2011-04-18T02:13:59.810 回答