1

我正在使用 Tabulator 插件在 jsp 页面内为我处理表格和排序。当我在标签内使用数据表时,它工作正常。我现在正试图从我们使用的系统返回 AJAX 数据。下面是系统返回的json示例。

如何配置 Tabulator 以使用数据并跳过响应的“平台”部分?

JSP脚本表

<script>
//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    placeholder:"No Data Set",
    columns:[
        {title:"PO", field:"po_number", sorter:"string", width:200},
    ],
});

//trigger AJAX load on "Load Data via AJAX" button click    
$("#ajax-trigger").click(function(){
   table.setData("https://mysystem.com/record/fieldList=po_number&alt=json");
});
</script>

JSON响应:

{“平台”:{“消息”:{“代码”:“0”,“描述”:“成功”},“记录”:[{“po_number”:“P000466”},{“po_number”:“P000791 "}, ], "recordCount": "2" }}

4

2 回答 2

0
$.ajax({
    url : "{{url_for('foo')}}", 
    data: {fooid:fooid},
    type: 'GET',
    contentType: "application/json;",
    success: function(receipts){var obj = $.parseJSON(receipts);
        var table = new Tabulator("#user-project-table", {
        layout:"fitData",
        data:obj,  
        etc,
        etc,
        etc...
        },
            error: function(error){
            console.log(error);
        }  
于 2019-05-14T08:44:12.553 回答
0

您可以使用ajaxResponse回调在将响应传递到表中进行处理之前对其进行更改。

我假设您想要传递记录属性:

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    placeholder:"No Data Set",
    columns:[
        {title:"PO", field:"po_number", sorter:"string", width:200},
    ],
    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.record; //return the recordproperty of a response json object
    },
});

我希望这会有所帮助,

干杯

奥利:)

于 2018-10-06T15:27:19.417 回答