DataTables请求第0行第1列FeathersJs的未知参数“1”

时间:2018-03-31 04:57:06

标签: mongodb datatables datatables-1.10 feathersjs

我有featherjs应用程序并尝试使用数据表。我正在使用ajax数据源,配置如下:

$('#example').DataTable({
      "ajax": {
          "url": "<url-placeholder>",
          "dataType": "json",
          "cache": true,  // this is to remove the '_' sent by datatables
          "data": function(params) {
            // Put additional parameters here
            return params;
          },
          "dataSrc": function(result) {
            var data = JSON.stringify(result.data);
            console.log(data);

            return data;
          },
          "columns": [
            { data: "_id" },
            { data: "name" },
            { data: "symbol" }
          ]
      }
    });

我有像这样的HTML

<table id="example">
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Symbol</th>
            </tr>
        </thead>
    </table>

服务器返回了这个:

  

[{“_ id”:“5abdd8548d46ed03dcb0ce2c”,“name”:“ABS-CBN”,“symbol”:“ABS”},{“_ id”:“5abdd8548d46ed03dcb0ce2d”,“name”:“AC PREF B2” ,“symbol”:“ACPB2”},{“_ id”:“5abdd8548d46ed03dcb0ce2e”,“name”:“Asiabest Gorup”,“symbol”:“ABG”},{“_ id”:“5abdd8548d46ed03dcb0ce2f”,“name”: “AC PREF B1”,“symbol”:“ACPB1”},{“_ id”:“5abdd8548d46ed03dcb0ce30”,“name”:“Anchor Land”,“symbol”:“ALHI”},{“_ id”:“5abdd8548d46ed03dcb0ce31” ,“name”:“Bogo Medellin”,“symbol”:“BMM”},{“_ id”:“5abdd8548d46ed03dcb0ce32”,“name”:“DAVINCI CAPITAL”,“symbol”:“DAVIN”},{“_ id” :“5abdd8548d46ed03dcb0ce33”,“name”:“FIRST METRO ETF”,“symbol”:“FMETF”},{“_ id”:“5abdd8548d46ed03dcb0ce34”,“name”:“IPeople”,“symbol”:“IPO”}, {“_ id”:“5abdd8548d46ed03dcb0ce35”,“name”:“Manila Bulletin”,“symbol”:“MB”}]

返回此错误的数据表。我现在已经搜索了好几个小时的答案。我坚持这个错误

  

DataTables警告:table id = example - 第0行第1列请求的未知参数“1”。有关此错误的详细信息,请参阅http://datatables.net/tn/4

1 个答案:

答案 0 :(得分:0)

我认为问题是因为你在Ajax块中有columns定义 - 它应该在外面:

$('#example').DataTable({
    "ajax": {
        "url": "<url-placeholder>",
        "dataType": "json",
        "cache": true, // this is to remove the '_' sent by datatables
        "data": function(params) {
            // Put additional parameters here
            return params;
        },
        "dataSrc": function(result) {
            var data = JSON.stringify(result.data);
            console.log(data);

            return data;
        }
    },

    "columns": [
        { data: "_id" },
        { data: "name" },
        { data: "symbol" }
      ]

});

我不相信DataTables支持cachedataType选项,但在首先移动columns块之后尝试删除它们。