【问题标题】:Tabulator JSON return from server制表符 JSON 从服务器返回
【发布时间】:2018-10-05 00:19:27
【问题描述】:

我正在使用 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"}, ], “记录数”:“2” }}

【问题讨论】:

    标签: jquery json ajax tabulator


    【解决方案1】:

    您可以使用 ajaxResponse 回调来更改响应,然后再将其传递到表中进行处理。

    我假设您想要传入 record 属性:

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

    希望对你有帮助

    干杯

    奥利 :)

    【讨论】:

      【解决方案2】:
      $.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);
              }  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        • 1970-01-01
        • 2019-05-24
        • 1970-01-01
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多