jQuery数据表显示html内容 [英] jQuery Datatables show html content

查看:384
本文介绍了jQuery数据表显示html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个jquery数据表,它使用服务器端处理来检索数据. 在这种情况下,其中一列包含html内容,因此我的服务器响应如下所示:

I have a jquery datatable on my page, which uses server side processing to retrieve data. In this case, one of the columns contains html content, thus my server responses looks like this:

"aaData": [ [1, "aaa", "<span class="myclass">html here</span>" ], ...

我尝试过

"aoColumnDefs": [ "aTargets":[2], "sType": "html" }

但是我仍然看到单元格内容就像是纯字符串一样. 我该怎么办?

But I still see the cell content as if it were plain string. What can I do?

推荐答案

使用以下版本制作工作版本

Made a working version with

"aoColumnDefs": [ 
    { "aTargets": [2], 
      "sType": "html", 
      "fnRender": function(o, val) { 
          return $("<div/>").html(o.aData[2]).text();
      } 
    }
]

使用jQuery解码HTML.

decoding back the html with jQuery.

这篇关于jQuery数据表显示html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆