jQuery DataTables fnrender url

时间:2015-01-23 13:04:43

标签: jquery ajax jsp servlets datatables

我正在使用jQuery DataTable来构建表。 Servlet输出如下所示:

{
  "iTotalRecords": 11,
  "iTotalDisplayRecords": 11,
  "aaData": [
    {
      "idUser": 1,
      "firstName": "example admin",
      "lastName": "surname",
      "password": "admin",
      "email": "admin@unb.by",
      "role": "ADMINISTRATOR"
    },
    {
      "idUser": 2,
      "firstName": "user",
      "lastName": "user",
      "password": "user",
      "email": "user@unb.by",
      "role": "USER"
    },
...

信息来自mysql。这是我的js代码:

<script>
        $(document).ready( function () {
        $('#users').DataTable({
            "bProcessing": true,
            "bServerSide": false,
            "sAjaxSource": "/IssueTracker/main/users",
            "aoColumns": [
                    { "mData": "idUser", "sClass": "center" },
                    { "mData": "firstName", "sClass": "center"},
                    { "mData": "lastName", "sClass": "center" },         
                    { "mData": "email", "sClass": "center"},  
                    { "mData": "role", "sClass": "center" },  
                    { "sClass": "center", 
                        "fnRender": function( oObj ) {
                            return '<a href="' + oObj.aData["idUser"] + '">' + oObj.aData["email"] + '</a>';
                        }   
                    }
            ]
        });
        } )
</script>

我只想获取实际数据,但我的jsp不显示链接......有什么问题?

1 个答案:

答案 0 :(得分:1)

在我自己的问题上找到答案。我们需要为链接列信息添加两个新函数,类型为:

{ "mData": function(source) { 
                        var resObj = {
                                'idUser' : source.idUser,
                                'email' : source.email,
                              }
                              return resObj;    
                    },
                    'mRender': function(resObj) {
                        var res = '<a href="url='+ resObj.idUser + '&email=' + resObj.email + '" >text</a>';
                        return res;
                      }
                    }