Javascript 在JQuery移动模板中解码html字符串

Javascript 在JQuery移动模板中解码html字符串,javascript,json,jquery,jquery-mobile,Javascript,Json,Jquery,Jquery Mobile,我正在使用jquery模板,我使用ajax请求填充这些模板。但是,返回的值之一是编码的HTML。我如何对它进行编码 我尝试过使用${$.mobile.html(Body.text()},但这对我不起作用 我的代码: Domain.Discussion.ListView = Domain.Discussion.ListView || { DiscussionPage: (function () { var onGetDiscussionSuccess = function

我正在使用jquery模板,我使用ajax请求填充这些模板。但是,返回的值之一是编码的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:


${Author}
角色尚未设置
${Created}
${$.mobile.html(Body.text()}


经过一次又一次的搜索,我终于在这里找到了解决方案:


在我的模板中使用
{{html Body}
非常有效。

你能给我们看看你的ajax响应吗?ajax调用返回json格式的一些项目。包括一个名为
Body
的项目,带有值(HTML编码)
Hejsan hoppsan

。我不明白的是你所说的“编码HTML”是什么意思?例如,
你好,世界

变成了
pHello,世界/p编码时为
。我现在找到了解决办法。哈哈,但是因为你喜欢答案,我们将停止对话。:)
<!-- 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 -->