【问题标题】:Retrieving HTML from MongoDB for use in Template从 MongoDB 中检索 HTML 以在模板中使用
【发布时间】:2013-05-10 00:36:23
【问题描述】:

我是 Meteor.js 和 MongoDB 的新手,所以这个问题可能有一个我想念的明显解决方案,但到目前为止我的搜索结果一无所获。

我的第一个 Meteor 项目是一个非常简单的博客。在 MongoDB 中,我有以下内容:

    Blog.insert({
      author: "Name Here",
      title: "Title Here",
      headerHTML: "This is my <b>very</b> first blog post.",
      bodyHTML: "What drives us to <em>solve</em> these types of problems?",
      date: new Date()
    });

然后在 blog.js 我有:

    if (Meteor.isClient) {
        Meteor.subscribe("blog");
        Template.posts.entry = function () {
          return Blog.find({});
        };
    }

最后在我的 HTML 中,我有以下内容

    ...
    <div class="row">
        {{> posts}}
    </div>
    ...
    <template name="posts">
      <div class="span12">
      {{#each entry}}
        {{author}}
        {{date}}
        {{title}}
        {{headerHTML}}
        {{bodyHTML}}
      {{/each}}
      </div>
    </template>

当我让应用程序运行 {{headerHTML}} 和 {{bodyHTML}} 指定的部分时,返回文字字符串。所以你会看到文本中的标签。我想要的是字符串被视为 HTML 并显示为这样。所以有些文字会加粗,我可以有链接等等......有人可以抛出我的任何智慧吗?

我尝试将把手放在各种 HTML 标记中(如 &lt;p&gt;{{bodyHML}}&lt;/p&gt;),但没有成功。

【问题讨论】:

    标签: mongodb meteor handlebars.js


    【解决方案1】:

    使用三个括号{{{ }}} 告诉meteor 不要转义你的html 字符串。

     {{{headerHTML}}}
     {{{bodyHTML}}}
    

    【讨论】:

    • 那太棒了!
    猜你喜欢
    • 2015-04-15
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多