【发布时间】:2019-03-30 07:47:50
【问题描述】:
当数据从服务器返回时,它永远不会填充到表中。
“我可以看到 'success' 回调的结果,但表格没有被填充,并且 'Processing...' 也继续显示”
使用 Angular 6、Jquery 数据表和 Spring Rest 控制器
npm install jquery --save
npm install datatables.net --save
npm install datatables.net-dt --save
npm install angular-datatables@6.0.0 --save
npm install @types/jquery --save-dev
npm install @types/datatables.net --save-dev
HTML代码
<table id=paymentHistoryTable datatable [dtOptions]="dtOptions class="table table-striped table-bordered" >
<thead>
<tr>
<th width="10%">Account ID</th>
<th width="12%">Name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Angular 代码如下
getPaymentHistoryPagination() {
this.dtOptions = {
pagingType: 'full_numbers',
serverSide: true,
processing: true,
ajax: {
url: this.baseUrl + '/getPaymentHistoryPagination',
type: 'POST',
contentType: 'application/json; charset=UTF-8',
error: function(xhr, error, code) { console.log("error::" +error); },
success: function(result) {console.log(JSON.stringify(result))},
data: function(data) {
return JSON.stringify(data);
}
}, columns: [
{ data: "customerId", title: 'Departure Time'},
{ data: "customerName", title: 'Customer Name'}
]
};
}
Java 控制器如下
@RequestMapping(value = "/getPaymentHistoryPagination", method = RequestMethod.POST)
@ResponseBody
public DataTableResponse getPaymentHistoryPagination1(@RequestBody @Valid SearchPropertyParamDTO dto) {
DataTableResponse dataTableResponse = new DataTableResponse();
try {
dataTableResponse.setDraw(1);
dataTableResponse.setRecordsFiltered(1L); //One record for testing
dataTableResponse.setRecordsTotal(1L);
Invoice invoice = new Invoice();
invoice.setCustomerId(111L);
invoice.setCustomerName("Abc");
List invoices = new ArrayList();
invoices.add(invoice);
dataTableResponse.setData(invoices);
} catch (Exception ex) {
//LOG.error("Error in getAllProperty", ex);
}
return dataTableResponse;
}
DataTableResponse 如下:
public class DataTableResponse {
private int draw =1;
private long recordsTotal ;
private long recordsFiltered ;
private List data;
}
预期结果:应该呈现表格 实际结果:获取消息处理 获得成功响应 {"draw":1,"recordsTotal":1,"recordsFiltered":1,"data":[{"id":null,"customerId":111,"customerName":"Abc"}]} 但没有填充数据
【问题讨论】:
标签: java jquery angular datatables