1

我正在处理从 json 数据在 DataTable 中创建链接。事情会好起来,但链接名称似乎不正确。无论我试图改变什么,它都会一直说“未定义”。这是我的代码:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        var oTable = $('#tablez').dataTable( {
            "bProcessing": true,
            "bJQueryUI": true,
            "sAjaxSource": 'inc/all_cars_json.php',
            "sPaginationType": "full_numbers",
            "aaSorting": [[ 0, "desc" ]],                   
             "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
                    $('td:eq(1)', nRow).html('<a href="car/=' + nRow[0] + '">' +
                        nRow[1] + '</a>');
                    return nRow;
                }
        } );
    } );
</script>

JSON数据:

{"aaData": [
["2715","Toyota","Soluna","VIOS 1.5E VVT-i","2007","\u0e14\u0e33","430,000"],
["2589","Toyota","","MIGHTY X","1995","\u0e40\u0e02\u0e35\u0e22\u0e27","159,000"],["2997","Mazda","Fighter","Freestyle CAB TURBO","2003","\u0e1a\u0e23\u0e2d\u0e19\u0e0b\u0e4c\u0e40\u0e07\u0e34\u0e19","329,000"],
["3002","Isuzu","Rodeo","LS 4WD","2000","\u0e1a\u0e23\u0e2d\u0e19\u0e0b\u0e4c\u0e17\u0e2d\u0e07","319,000"],
["3126","Toyota","Hilux","TIGER D4D CAB","2003","\u0e02\u0e32\u0e27","465,000"],["3127","Mitsubishi","Triton","DID Commonrail","2006","\u0e1a\u0e23\u0e2d\u0e19\u0e0b\u0e4c\u0e17\u0e2d\u0e07","455,000"],
["3128","Honda","City","1.5 i-VTEC","2009","\u0e14\u0e33","0"]
]}

这是预览:

在此处输入图像描述 问题是:在这种情况下,如何让链接标题和值 (nRow[0]) 起作用。问候,

4

2 回答 2

3

这可以使用以下方法完成:

     "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
            $('td:eq(1)', nRow).html('<a href="car/=' + nRow[0] + '">' +
                $('td:eq(1)', nRow)[1].textConent + '</a>');
            return nRow;
        }

或命名您的列

"aoColumns": [
              { "bSortable": false, "sWidth": "34px", "mDataProp": "Id" },
              { "mDataProp": "Brand" },
              { "mDataProp": "Type" },
              { "mDataProp": "SubType" },
              { "mDataProp": "Year" }]

然后你可以使用这个:

 "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
        $('td:eq(1)', nRow).html('<a href="car/=' + nRow[0] + '">' +
            aData.Brand + '</a>');
        return nRow;
    }
于 2012-12-28T09:22:06.673 回答
0

在函数中更改nRow为。aDatafnRowCallback

"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                    $('td:eq(1)', nRow).html('<a href="car/=' + aData[0] + '">' +
                        aData[1] + '</a>');
                }
于 2013-08-04T04:48:32.270 回答