【发布时间】:2012-07-23 12:57:47
【问题描述】:
我得到一个 json 提要,它返回带有 HTML 标记的内容(因为它是从 CMS 生成的)。 json feed 本身很好,但它会在内容中呈现 html 标签,如下所示:
<p>First para</p><p>Second para</p>
我希望它像这样呈现格式化的 html 标签:
第一段
第二段
我尝试使用 php 'html_entity_decode' 和 'htmlentities' 来操作内容,然后返回 json 无济于事。
我正在使用 jquery 模板来呈现 json 数据,如下所示:
var markup = '<h5>${title}</h5><p>${date}</p>${content}';
关于我是否应该将 $content 格式化为 jquery .html() 对象的任何想法?
编辑:这是模板代码 - 我在其中尝试了 .html() 但只有错误?
function getArticle(type, id) {
$.getJSON("http://www.jsonexample.com/api/?type="+ type +"&aid="+ id +"", function(json) {
var markup = '<h5>${title}</h5><p>${date}</p>${content}';
$.template( "articleTpl", markup );
$.tmpl( "articleTpl", json ).appendTo('#article');
});
}
这似乎可行,尽管在测试版中注意 {{html content}}:
var markup = '<h5>${title}</h5><p>${date}</p>{{html content}}';
人们对在应用中使用此功能有何看法?
【问题讨论】:
-
显示渲染模板的代码。
-
代码更新 ravi - 关于如何使用 .html() 方法包装 $content 的任何想法?