Meteor-如何在三个括号中呈现脚本标记

Meteor - How to render script tags in triple brackets?

本文关键字:脚本 三个 Meteor-      更新时间:2023-09-26

我有一个简单的文档,如下所示:

{
    "_id" : "gQgFzrxCecXxzuCEq",
    "content" : "'n# 5. Bonus: Meteor SSL Configuration.'n'n<script>console.log('hello world');</script>'n<script src='"https://gist.github.com/LeCoupa/9877434.js'"></script>'n'n",
    "title" : "Node #5: Building a REST API with Restify and Monk"
}

当我尝试用{{{content}}}呈现内容时,<script>标记不会被评估,甚至不会出现在DOM中(看起来三方括号呈现会删除它们)。

这是模板:

<template name="JournalArticleContent">
  <div class="article-content article-content-complete">{{{content}}}</div>
</template>

更准确地说,我试图渲染的脚本是一个要点:

<script src="https://gist.github.com/LeCoupa/28bf7505fe4c5b439da5.js"></script>

我该怎么做才能让Meteor显示和评估它们?

您应该能够通过创建服务器API(路由器)来响应content中的html来实现这一点。并使用ajax调用在客户端获得您想要的内容。

// server side
Meteor.router.add('/api/getContent', function(){
  // retrieve your "content" here ...
  return [200, YourContent];
});
// client side, just use ajax to retrieve your content

编辑

您可能需要查看BrowserPolicy,以防内容来自外部源