0

好吧,这个让我发疯了。

我正在尝试创建一个 jQuery 数据表并不断收到错误消息:
DataTables 警告(表 id = 'properties'):添加的数据(大小未定义)与已知的列数不匹配 (9)

我有一个设置了 9 列的表(即<th>html 中的 9 个块)

Javascript 看起来还不错(尽管如果有人能肯定地验证它会有所帮助):

$tableProperties = $('#properties').dataTable({
    sDom: '<"dataTables_header"<"dataTables_toolbar">rl>t<"dataTables_footer"ip>',
    oLanguage: { sLengthMenu: "Show _MENU_ lines", sInfo: "Showing _START_ to _END_ of _TOTAL_ lines" },
    iDisplayLength: <%: ShusterConnect.ConfigurationSettings.MgtPropertiesPerPage %>,
    aLengthMenu: [[10, 20, 50, -1], [10, 20, 50, "All"]],
    bPaginate: true,
    sPaginationType: "listbox",
    bLengthChange: true,
    bFilter: false,
    bInfo: true,
    bAutoWidth: true,
    bProcessing: true,
    bServerSide: true,
    sAjaxSource: "/property/QueryAllProperties",
    aaSorting: [[ 5, "asc" ]], // default sorting column is Management Company
    fnServerData: function (sSource, aoData, fnCallback) {
        $.post(sSource, aoData, fnCallback);
    },
    fnRowCallback: function (tr, record, iDisplayIndex, iDisplayIndexFull) {
        $('td:eq(7)', tr).html(renderActionTemplate(record[7], $('td:eq(4)', tr).text()));
        $('td:eq(7)', tr).css("white-space", "nowrap");
        if ($('td:eq(4)', tr).text() != "Yes")
            $(tr).css("background-color", "#c0c0c0");
        return tr;
    },
    aoColumns: [
        { "mDataProp": "ShusterPropertyID" },
        { "mDataProp": "ShusterCustomerID" },
        { "mDataProp": "BEPropertyID" },
        { "mDataProp": "BEUserName" },
        { "mDataProp": "IsManagementCompany" },
        { "mDataProp": "ManagementCompany" },
        { "mDataProp": "MappingFileType" },
        { "mDataProp": "Action", "bSortable": false},  // action
        { "mDataProp": "ParentId" } //Parent Id 
    ],
    });
});

我的 JSON 返回一个 aaData 集,每条记录有 9 个值: {"sEcho":"1","iTotalRecords":147,"iTotalDisplayRecords":147,"aaData":[{"ShusterCustomerId":"1057","ShusterPropertyId":"DEV","BEPropertyId":"4368058011","BEUserName":"Devon Oaks","IsManagementCompany":"","ManagementCompany":"Eliza Jennings Senior Care Network","MappingFileType":"Default","Action":"57","ParentId":""},{"ShusterCustomerId":"1058","ShusterPropertyId":"ELIZA","BEPropertyId":"4368056561","BEUserName":"Eliza Jennings Home","IsManagementCompany":"","ManagementCompany":"Eliza Jennings Senior Care Network","MappingFileType":"Default","Action":"58","ParentId":""}, ... {"ShusterCustomerId":"1168","ShusterPropertyId":"WESC","BEPropertyId":"3008297838","BEUserName":"Wesley Court Methodist Retirement Community","IsManagementCompany":"","ManagementCompany":"Sears Methodist Retirement System","MappingFileType":"PathLinks","Action":"243","ParentId":"232"}]}

所以...到底发生了什么?我错过了什么重要的事情吗?任何建议将不胜感激。

PS我确实花了一个小时搜索互联网(和StackOverflow),但找不到任何指向问题的东西......

4

1 回答 1

1

json数据格式应该是这样的:{"sEcho":17,"iTotalRecords":35,"iTotalDisplayRecords":35,"aaData":[["2012-12-01","1"],["2012 -12-27","1"],["2012-12-26","1"],["2012-12-27","1"],["2012-12-19","1 "],["2012-12-27","1"],["2012-12-27","1"],["2012-12-27","1"],["2012-12 -27","1"],["2012-12-27","1"],["2012-12-27","1"],["2012-12-21","1"] ,["2012-12-27","1"],["2012-12-25","1"],["2012-12-26","1"],["2012-01-03 ","1"],["2012-11-23","1"],["2012-12-02","1"],["2012-11-22","1"],["2012-12-24","1"],["2012-11-14","1"],["2012-11-22"," 1"],["2012-11-23","1"],["2012-11-22","1"],["2012-11-22","1"],["2012- 11-26","1"],["2012-12-20","1"],["2012-12-17","1"],["2012-12-21","1" ],["2012-12-12","1"]]}2012-12-21","1"],["2012-12-12","1"]]}2012-12-21","1"],["2012-12-12","1"]]}

因此,要获得这种格式的数据,请执行以下操作: $rResult = $this->db->query($sQuery); $rResult = $rResult->result_array();

foreach ($rResult as $aRow) {
     $row = array();


 foreach ( $aRow as $key => $val ) {





  $row[] = $val;
}

      $output['aaData'][] = $row;
    }
echo json_encode( $output );
于 2013-05-21T06:12:48.740 回答