0
我正在使用jQuery模板,使用ajax请求填充它。但是,返回的值之一是编码的HTML。我如何编码它?在jQuery Mobile模板中解码html字符串
我试过使用${$.mobile.html(Body).text()}
,但那对我没有用。
我的代码:
Domain.Discussion.ListView = Domain.Discussion.ListView || {
DiscussionPage: (function() {
var onGetDiscussionSuccess = function (data) {
$("#discussionsList ul").remove();
$("#discussionListItem").tmpl(data.DiscussionsResult).appendTo("#discussionsList", function() {
reloadAndFixPanelContent()
});
}
var onGetDiscussionError = function() {
console.log("Error occured when retrieving discussions");
}
$.ajax({
url: absolutePath + "Discussions",
headers: { "Accept": "application/json; odata=verbose" },
success: onGetDiscussionSuccess,
error: onGetDiscussionError
});
}())
};
HTML:
<!-- Discussion replies -->
<script id="replies" type="text/x-jquery-tmpl">
<div class="message message-first">
<div class="message-header">
<div class="message-header-user">
<h1>${Author}</h1>
<h2>Role not set yet</h2>
</div>
<div class="message-header-date">${Created}</div>
</div>
<div class="message-content">
<span>${$.mobile.html(Body).text()}</span>
<hr />
</div>
</div>
</script>
<!-- /Discussion replies -->
你能告诉我们你的ajax响应吗? – Gajotres 2013-05-02 10:12:48
ajax调用返回,json格式化,几个项目。包含一个名为'Body'的值(HTML编码)'
我不明白的是“编码HTML”是什么意思? – Gajotres 2013-05-02 10:36:11