[英]Meteor - How to render script tags in triple brackets?
我有一个简单的文档,像这样:
{
"_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(路由器),为您回应的HTML做到这一点content
。 并使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.