node.js - 与 Jade 的动态链接

标签 node.js express pug

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

最佳答案

很确定你可以这样做:

a(href=post.title)

关于node.js - 与 Jade 的动态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5697863/

相关文章:

javascript - 使用带有 Node 的简单 js 提示到 Electron 应用程序

node.js - Electron:如何在我们的index.html中导入或包含使用npm包管理器安装的CSS?

javascript - Mongoose : $where unequal

node.js - 如何在 NodeJS 中创建具有唯一 id 的路由

css - 使用 NodeJS、Jade 和 PhantomJS 创建 PDF

javascript - 如何将多个 JSON 对象用于单个 NodeJS/Jade 合并

javascript - 从 Mongoose 结果匿名函数返回父函数

node.js - Swagger、Express 和 Node.js 中的 "Cannot get/"

node.js - 如何在一个请求中使用两次或多次回调发送响应

javascript - 将变量传递给 onClick 函数