与 Jade 的动态链接

发布于 2024-11-02 03:31:42 字数 578 浏览 1 评论 0原文

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

Using Jade + Express + Node.js + Mongoose + MongoDB for my app, but this issue I ran into is likely in Jade:

I have some code as follows that prints a list of posts by title, author

div#articles
      -each post in records
         div.article
            #{post.title} was written by #{post.author}
            <a href ="#{post.title}"> Link to Article </a>

Now I want to the link in written Jade instead of HTML, but when I replace the line with

a(href='#{post.title}')

it links to /#{post.title} instead of the variable name such as /newpost1. Doing it as

a(href=#{post.title})

returns an error. I'm sure this is a syntax issue, but I can't find the solution in the GitHub documentation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

优雅的叶子 2024-11-09 03:31:42

很确定你可以这样做:

a(href=post.title)

pretty sure you can just do:

a(href=post.title)
鱼窥荷 2024-11-09 03:31:42

玉:

- 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>

jade:

- 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文