2016-05-28 54 views
0

我是一個初學程序員,試圖製作一個簡單的Meteor應用程序,我可以通過它的REST API顯示來自我的另一個站點的數據(該站點運行在Joomla和我正在使用jBackend作爲REST API--但這僅僅是上下文,並不適用於這個問題)如何呈現在JSON響應中返回的'轉義'HTML塊

當我發送一個GET請求並收到一個響應時,返回的JSON爲我提供了我的文章內容一個巨大的HTML塊 -

{ 
    "status": "ok", 
    "id": "23", 
    "title": "The Ivy", 
    "alias": "the-ivy2", 
    "featured": "0", 
    "content": "<div class=\"venue-intro\">\r\n\t<h1>\r\n\t\t\t\t\t<a href=\"index.php?option=com_content&view=article&id=23:the-ivy2&catid=14:leisure-activites\" title=\"The Ivy\">\r\n\t\t\t\t\tThe Ivy\r\n\t\t\t\t\t</a>\r\n\t\t\t</h1>\r\n\r\n\t<div class=\"row\">\r\n\t\t<div class=\"col-md-5\">\r\n\t\t\t\t\t\t\t<div class=\"venue-intro-img\">\r\n\t\t\t\t\t\t\t\t\t\t\t<a href=\"index.php?option=com_content&view=article&id=23:the-ivy2&catid=14:leisure-activites\" title=\"The Ivy\">\r\n\t\t\t\t\t\t\t\t\t\t\t<img src=\"http://localhost/stc/images/stories/com_form2content/p4/f20/thumbs/theIvy.jpg\">\r\n\t\t\t\t\t\t\t\t\t\t\t</a>\r\n\t\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t</div>\r\n\t\t<div class=\"col-md-7\">\r\n\t\t\t\t\t\t\t<p><p>The Ivy is situated in the heart of London's West End, close to Leicester Square, Shaftsbury Avenue and the vibrant quarters of Covent Garden and Soho. Open late each night, the restaurant is...</p>\r\n\t\t\t\t\t</div>\r\n\t</div>\r\n</div><div class=\"venue-main\">\r\n<h1>The Ivy</h1>\r\n\t<img src=\"http://localhost/stc/images/stories/com_form2content/p4/f20/theIvy.jpg\" class=\"venue-main-img\">\r\n\t<p><p>The Ivy is situated in the heart of London's West End, close to Leicester Square, Shaftsbury Avenue and the vibrant quarters of Covent Garden and Soho. Open late each night, the restaurant is also perfect for post theatre dinner. The Royal Opera House, Coliseum and all other theatres are a short walk away. The space can be arranged and dressed to suit your event- whatever the style and can accommodate 25-120 people.</p>\r\n<p>The room comes with a baby grand piano, fresh flowers, candles and place cards. AV equipment and musicians can be arranged and our event production company, Urban Caprice, can re-design and style the room for any event, supplying props, lighting and much more. We create seasonal menus especially for the Private Room, but let us know if you have any other favourite dishes and we'd love to try and include them.</p>\r\n<p><a href=\"http://www.the-ivy.co.uk/\" target=\"_blank\">http://www.the-ivy.co.uk/</a></p></p>\r\n</div>" 
} 

我想是因爲我的應用程序來渲染這一塊,但我不能管理它 - 這是我一直在努力,到目前爲止 -

Template.articles.helpers({ 
    'content': function() { 
    return $('<div />').html(this.content).text(); 
    } 
}); 

使用這種方法使我這個輸出 -

<div class="venue-intro"> <h1> <a href="index.php?option=com_content&amp;view=article&amp;id=23:the-ivy2&amp;catid=14:leisure-activites" title="The Ivy"> The Ivy </a> </h1> <div class="row"> <div class="col-md-5"> <div class="venue-intro-img"> <a href="index.php?option=com_content&amp;view=article&amp;id=23:the-ivy2&amp;catid=14:leisure-activites" title="The Ivy"> <img src="http://localhost/stc/images/stories/com_form2content/p4/f20/thumbs/theIvy.jpg"> </a> </div> </div> <div class="col-md-7"> <p></p><p>The Ivy is situated in the heart of London's West End, close to Leicester Square, Shaftsbury Avenue and the vibrant quarters of Covent Garden and Soho. Open late each night, the restaurant is...</p> </div> </div> </div><div class="venue-main"> <h1>The Ivy</h1> <img src="http://localhost/stc/images/stories/com_form2content/p4/f20/theIvy.jpg" class="venue-main-img"> <p></p><p>The Ivy is situated in the heart of London's West End, close to Leicester Square, Shaftsbury Avenue and the vibrant quarters of Covent Garden and Soho. Open late each night, the restaurant is also perfect for post theatre dinner. The Royal Opera House, Coliseum and all other theatres are a short walk away. The space can be arranged and dressed to suit your event- whatever the style and can accommodate 25-120 people.</p> <p>The room comes with a baby grand piano, fresh flowers, candles and place cards. AV equipment and musicians can be arranged and our event production company, Urban Caprice, can re-design and style the room for any event, supplying props, lighting and much more. We create seasonal menus especially for the Private Room, but let us know if you have any other favourite dishes and we'd love to try and include them.</p> <p><a href="http://www.the-ivy.co.uk/" target="_blank">http://www.the-ivy.co.uk/</a></p><p></p> </div> 

這看起來像完全有效的HTML但問題是,瀏覽器是不是渲染它是這樣 - 它只是從字面上輸出這一長串。 :(

在一天結束的時候,我希望能夠渲染我收到我的JSON響應的HTML。

任何幫助表示讚賞。

回答

0

火焰有使用方式而不是正常的兩個三花括號來呈現raw HTML strings

{{{content}}} 
在你的模板

應該呈現內容,provid編輯助手返回有效的HTML。

小心使用它,特別是如果它包含用戶生成的內容。