簡體   English   中英

流星-如何在三括號中呈現腳本標簽?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM