数据表参数 0 行 0 列 0 错误

Datatables param 0 row 0 column 0 error

我的问题是参数 0 行 0 列 datables 的 datables 错误 datables.net/tn/4。我正在使用 ajax 检索我的数据并填充 table。

这里是 ajax

        $.ajax({
        url: 'DAL/WebService1.asmx/FabGuide',
        method: 'post',
        dataType: 'json',
        success: function (data) {
            console.log(data);
            $("#datatable").dataTable({
                data: data,
                columns: [
                    { 'data:': 'accountCode' },
                    { 'data:': 'accountValue' },
                    { 'data:': 'description' },
                    { 'data:': 'manufacturer' },
                ]
            });
        }
    });

这是table

                        <table id="datatable">
                            <thead>
                                <tr>
                                    <th>accountCode</th>
                                    <th>accountValue</th>
                                    <th>description</th>
                                    <th>manufacturer</th>
                                </tr>
                            </thead>
                        </table>

这是我的数组的样子

可能我看了很久 谢谢

你可以试试这个方法:

$.ajax({
    url: 'DAL/WebService1.asmx/FabGuide',
    method: 'post',
    dataType: 'json',
    success: function (data) {
        var arrData = [];
        data.forEach(function(item){
            var aux = [];
          aux.push(item.accountCode);
          aux.push(item.accountValue);
          aux.push(item.description);
          aux.push(item.manufacturer);
          arrData.push(aux);
        });
        $("#datatable").dataTable({
            data: arrData,
            columns: [
                { title: 'accountCode' },
                { title: 'accountValue' },
                { title: 'description' },
                { title: 'manufacturer' },
            ]
        });
    }
});

data属性接收数组元素的数组;检查文件:https://www.datatables.net/examples/data_sources/js_array.html

您的初始化代码中有错字 - 没有选项 data:,应该是 data

正确代码如下:

// ... skipped ...

$("#datatable").dataTable({
   data: data,
   columns: [
      { 'data': 'accountCode' },
      { 'data': 'accountValue' },
      { 'data': 'description' },
      { 'data': 'manufacturer' }
   ]
});

// ... skipped ...