jTemplate和MicrosoftAjaxTemplates编码或解码html(浏览器不渲染为html)

时间:2010-01-23 16:02:33

标签: asp.net javascript jtemplate

我使用jTemplate在我的页面中显示rss项目。但是每个项目的描述都没有正确呈现。

我的模板是:

<table>
  <thead>
    <tr>
      <th>Date</th>
      <th>Title</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    {#foreach $T.Items as post}
    <tr>
      <td>{$T.post.PubDate}</td>
      <td><a href="{$T.post.Link}">{$T.post.Title}</a></td>
      <td>{$T.post.Description}</td>
    </tr>
    {#/for}
  </tbody>
</table>

但是当渲染页面时,我在描述栏中看到了标签(或编码标签)而不是渲染html:

  

&amp; lt; table border = 0 width = valign = top   cellpadding = 2 cellspacing = 7&amp; GT;&安培;   LT; TR&安培; GT;&安培; lt; td width = 80   align = center valign = top&amp; GT;&安培; LT;字体   风格=“字体大小:85%;字体家庭:Arial字体,无衬线”&安培;   GT; ....

当服务器端的html解码时,请参阅:

  

&lt; table border = 0 width = valign = top   CELLPADDING = 2   CELLSPACING = 7个;&LT; TR&GT;&LT; TD   width = 80 align = center   VALIGN =顶部和GT;&LT;字体   风格= “字体大小:85%;字体家庭:Arial字体,无衬线” &GT; ....

有什么问题?

注意:我使用MicrosoftAjaxTemplates测试并看到同样的问题,但是当使用字符串时,它就像$('。desc')。append('any html tag');

1 个答案:

答案 0 :(得分:2)

默认情况下,jTemplates会转义HTML。您可以通过更改optional settings object上的属性作为第三个参数来更改它,如下所示:

.setTemplate("#template", null, { filter_data: false });