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

Decode html string in JQuery Mobile template

本文关键字:移动 JQuery html 字符串 解码      更新时间:2023-09-26

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

经过搜索和搜索,我终于找到了解决方案:jQuery tmpl:如何渲染Html?

在我的模板中使用{{html Body}}效果很好