【问题标题】:Want to insert data with html tag in mongodb and render it on browser想在mongodb中插入带有html标签的数据并在浏览器上渲染
【发布时间】:2015-12-03 20:21:23
【问题描述】:

我正在使用 mongoDB 开发节点 js。我能够在数据库中插入数据。我有大量内容要插入一些 <p><li> 标签。当我获取数据并在浏览器上呈现它时,它只显示标签。我希望该标签按其含义进行转换。 示例:

<p>this is the content</p>

它在浏览器上也显示相同。 这应该转换为“这是内容”。

在查看页面我有以下代码。

    {{#each doc}}
    <div class="content">
    {{this.content}}            
    </div>
    {{/each}}

【问题讨论】:

  • 这与 MongoDB 无关,而是与您将 HTML 代码插入要呈现的 HTML 文档的方式有关。要获得帮助,你必须描述你是如何做这部分的。
  • 假设您使用的是jade,您需要将内容打印为原始HTML !{content}
  • @FlorianWinter:请看看我的编辑。
  • @Cyrbil : 你是说将我的代码编辑为 !{{this.content}}??
  • 你的模板引擎是什么?

标签: html node.js


【解决方案1】:

您需要将内容输出为原始 html,否则模板引擎会转义您的 html 内容。

看起来您正在使用车把:使用三重 {{{ }}} 括号

{{#each doc}}
<div class="content">
{{{this.content}}}            
</div>
{{/each}}

【讨论】:

  • 感谢您的大力支持
猜你喜欢
  • 2018-05-29
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 1970-01-01
  • 2021-09-15
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
相关资源
最近更新 更多