1

我在我的视图中使用了 jQuery Datatable,如下所示;

<table id="CategoryGrid">
    <thead>
        <tr>
            <th>Id</th>
            <th>
                Name
            </th>
            <th>
                Description
            </th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

以及 Datatable 的 javascript 代码;

    var catGrid = $('#CategoryGrid').dataTable({
        "bPaginate": true,
        "bServerSide": true,
        "bProcessing": true,
        "sAjaxSource": "@Url.Action("CategoriesGet")",
        "aoColumns": [
            {
                "sName": "CategoryId",
                "bSearchable": false,
                "bSortable": false,
                "fnRender": function (oObj) {
                    return '<a href=\"Company/Details/' + oObj.aData[0] + '\">View</a>';
                }
            },
            { "sName": "CategoryName" },
            { "sName": "CategoryDescription" }
        ]
    });

返回的JSON数据如下;

{"sEcho":"1","iTotalRecords":10,"TotalDisplayRecords":10,"aaData":[["1","For Sale","asdfasdf"],["2","Jobs","asdfasdfasdf"],["3","Classes","asdfasdf"],["4","Vehicles","asdfasdsadfa"],["45","test","asdff"],["46","asfd","sdf"],["47","test","sdf"],["48","another test","sfsdfsdf"],["49","another test","sdfsdfsdf"],["50","asfd","asdf"]]}

为什么我在 NaN 条目中显示 1 到 NaN

4

1 回答 1

4

看起来你在iTotalDisplayRecordsword 中有错字,你忘记了i字母前缀......

另外,看看这个服务器端处理

一般来说,您从服务器的回复应包含:、、iTotalRecordsiTotalDisplayRecords属性...sEchoaaData

sEcho :从客户端发送的未更改的 sEcho 副本。这个参数会随着每次抽奖而改变(它基本上是一个抽奖次数)——所以实现这一点很重要。请注意,出于安全原因,强烈建议您将此参数“强制转换”为整数,以防止跨站点脚本 (XSS) 攻击。

于 2013-04-21T14:06:14.747 回答