从 ajax 请求将嵌套数据加载到制表符 table

Load nested data to tabulator table from ajax request

我从商店买了一件 api。我收回 json 请求这样的结构 第一级 3 条记录

数据,error_no,消息

在二级里面数据

data.items, data.total_pages, data.total_results

里面 data.items(3 级)有我需要加载到制表符 table 的记录。 所以这个嵌套记录我只需要提取和加载项目到 table ? select 他们怎么可能?

function loadTableTab(tableData) {
    var table = new Tabulator("#table", {
        data:tableData, //set initial table data
        columns:[
            {title:"product_title", field:"product_title"},
            {title:"sale_price", field:"sale_price"},
        ],
    });
}

您可以使用 ajaxResponse 回调以 Tabulator 可以处理的方式格式化数据,它在响应中传递并且应该 return table 数据的数组,所以在你的情况下它应该是:

function loadTableTab(tableData) {
    var table = new Tabulator("#table", {
        data:tableData, //set initial table data
        ajaxResponse:function(url, params, response){
            return response.data.items; // return the array of table items
        },
        columns:[
            {title:"product_title", field:"product_title"},
            {title:"sale_price", field:"sale_price"},
        ],
    });
}