【问题标题】:How to set json data into jquery 1.7 datatable如何将json数据设置为jquery 1.7数据表
【发布时间】:2016-06-09 23:07:07
【问题描述】:

我使用的是 jquery 1.7.1,因为这是我的旧项目,所以我无法更改它。我在将控制器返回的 json 数据设置为 javascript 对数据表进行的 ajax 调用时遇到问题。 以下是我的ajax调用

$.ajax({
    type : "post",
    url : "myController",
    dataType : 'json',
    data : 'operation=getUploaded&filename=' + filename,
    success : function(data) {

        console.log("<<<<<<<<<<<data<<<<<<<<<<<", data.Data[0]);
        $('#example').dataTable({
            "aoData": data.Data[0],
            "aoColumns": [
                { "mDataProp": "id" },
                { "mDataProp": "point" },
                { "mDataProp": "floor" },
                { "mDataProp": "custAccNo" },
                { "mDataProp": "data" }
        ]

        });
    }
}); 

这是我返回的 json:

{
   "Data": [{
       "id": 4534534,
       "point": "45",
       "floor": "345",
       "custAccNo": "000000001",
       "data": "ABC",
       "fileName": "23rbc.rti",
       "grid": "001"
   }]
}

这是我的 jsp 中的表格:

<div class="container"> 
    <table cellpadding="0" cellspacing="0" border="0" class="dataTable" id="example">
        <thead>
            <tr>
                <th>id</th>
                <th>point</th>
                <th>floor</th>
                <th>custAccNo</th>
                <th>data</th>
            </tr>
        </thead>
    </table>
</div>

有什么建议吗?

【问题讨论】:

  • 您遇到错误了吗?请发布您面临的确切问题。
  • 空数据表显示,没有错误。 @Hector
  • 正确的设置是aaData,而不是aoData ...

标签: jquery json ajax datatables


【解决方案1】:

您的数组是 data.Data 而不是 data.Data[0] 这是数组中的第一个对象

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-09
    • 2011-08-01
    • 1970-01-01
    • 2016-04-27
    • 2019-05-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    相关资源
    最近更新 更多