【问题标题】:Load nested data to tabulator table from ajax request从 ajax 请求将嵌套数据加载到制表器表
【发布时间】:2019-11-17 14:04:42
【问题描述】:

我有一个来自商店的 api。我在 json 请求中收回了这样的结构,第一级有 3 条记录

数据、error_no、msg

在第二层里面数据

data.items、data.total_pages、data.total_results

内部 data.items(3 级)有我需要加载到制表表的记录。 所以这个嵌套记录我只需要提取和加载项目到表吗?如何选择它们?

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"},
        ],
    });
}

【问题讨论】:

  • 你能显示你传递给tableData的值吗

标签: javascript json datatables tabulator


【解决方案1】:

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

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"},
        ],
    });
}

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    相关资源
    最近更新 更多