我收到错误 "未捕获的SyntaxError:意外的令牌{-dataTables.bootstrap.min.css:1"
作为一名初学者,我尽了最大努力,但却无法找到解决方案。而servlet的响应是Json Data 这是以下格式
{
"TransferMoneyHistory":[
{
"amount":1000,
"transactionDate":{
"date":1,
"hours":5,
"seconds":0,
"month":0,
"timezoneOffset":-330,
"year":70,
"minutes":30,
"time":2,
"day":4
}
}
]
}
我需要将列索引显示为" Amount"和"交易" 感谢
$(document).ready(function () {
$("#DepositDataTable").DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "DepositHistory",
"type": "Post",
"success": function (jsonResponse) {
console.log(jsonResponse)
}
},
"columns": [
{"jsonData": "Amount"},
{"jsonData": "TransactionDate"}
]
});
});
答案 0 :(得分:0)
要使用jQuery DataTable,我建议您先查看https://datatables.net/reference/。 在您的情况下,要正确显示数据: 1. Json响应应该如下所示
{
"recordsFiltered" : 1,
"data" : [ {
"amount":1000,
"transactionDate":{
"date":1,
"hours":5,
"seconds":0,
"month":0,
"timezoneOffset":-330,
"year":70,
"minutes":30,
"time":2,
"day":4
}
} ],
"draw" : 2,
"recordsTotal" : 1
}
2.通过引用https://datatables.net/reference/option/columns,列应设置为
"columns": [
{
// title of the column
"title":"Amount",
// the property of data in json response to show
"data": "amount"
},
{
"title":"TransactionDate",
"render": function(data, type, row, meta){
// need further handle for nested property,
// refer to
https://datatables.net/reference/option/columns.render
}
}
]