制表符由于数据类型无效而无法处理数据

问题描述 投票:0回答:1

我正在尝试学习如何从JSON数据将数据加载到制表符中。我遇到了错误

tabulator.min.js:3 Data Loading Error - Unable to process data due to invalid data type 
Expecting: array 
Received:  object 

我想我需要使用ajaxResponse:function,但不确定如何使用。这是我正在使用的代码段。

//define data

var data = [ ]

  var table = new Tabulator("#tabulator-example", {
        height:800,
        data:data,
        layout:"fitDataStretch",
         //ajaxURL:"omdata.json",
        // ajaxProgressiveLoad:"scroll",
        // paginationSize:20,
        placeholder:"No Data Set",
        autoResize:true,
        ajaxContentType : "application/json; charset=utf-8",
        ajaxContentType:"json",
        tooltips:true,
        addRowPos:"top",
        resizableRows:true,
      initialSort:[
         {column:"feature", dir:"asc"},,
      ],
      columns:[
       <REMOVED>
      ],
    });
    //trigger AJAX load on "Load Data via AJAX" button click
    document.getElementById("ajax-trigger").addEventListener("click", function(){
    table.setData("omdata.json");
    });

    $("#tabulator-controls input[name=feature]").on("keyup", function(){
      table.setFilter( "feature", "like", $(this).val())
    });
html tabulator
1个回答
0
投票

好吧,我知道了。这是我所做的

var table = new Tabulator("#tabulator-example", {
        height:800,
        data:data,
        layout:"fitDataStretch",
         //ajaxURL:"omdata.json",
        // ajaxProgressiveLoad:"scroll",
        // paginationSize:20,
        placeholder:"No Data Set",
        autoResize:true,
        ajaxContentType : "application/json; charset=utf-8",
        ajaxContentType:"json",
        tooltips:true,
        addRowPos:"top",
        resizableRows:true,
      initialSort:[
         {column:"feature", dir:"asc"},,
      ],
      columns:[
       <REMOVED>
      ],

      ajaxResponse:function(url, params, response){
        //url - the URL of the request
        //params - the parameters passed with the request
        //response - the JSON object returned in the body of the response.

        return response.data; //pass the data array into Tabulator
    },
}),
© www.soinside.com 2019 - 2024. All rights reserved.