2013-05-02 14 views
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 --> 
+0

你能告訴我們你的ajax響應嗎? – Gajotres 2013-05-02 10:12:48

+0

ajax調用返回,json格式化,幾個項目。包含一個名爲'Body'的值(HTML編碼)'

Hejsan hoppsan!

'。 – 2013-05-02 10:25:51

+0

我不明白的是「編碼HTML」是什麼意思? – Gajotres 2013-05-02 10:36:11

回答