我正在尝试使用angularjs datatable和rest api调用来实现数据服务器端分页。我面临的问题是当我点击分页上的下一个按钮时,从服务器发送的数据在成功回调后没有加载到数据中。它显示消息“处理..”因此卡住了。这是我的控制器代码。
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
headers: {
'Content-Type': 'application/json',
'Authorization': $rootScope.currentUser.authToken
},
error : function (xhr,status,error)
{
if(status === 401){
window.location.replace("/pc-web/userHome");
errorFlash(error);
}
},
url: GET_ROOMLIST,
type: 'GET'
})
// or here
.withDataProp(function(json) {
console.log(json);
return json.data;
})
.withOption('processing', true)
.withOption('serverSide', true)
.withDOM('frtip')
.withDisplayLength(9)
.withOption('createdRow', function (row) {
// Recompiling so we can bind Angular directive to the DT
$compile(angular.element(row).contents())($scope);
})
.withOption('saveState', true)
.withOption('order', [0, 'asc'])
.withPaginationType('simple_numbers')
.withButtons([
{
extend: 'csvHtml5',
text: 'Export',
titleAttr: 'CSV',
exportOptions: {
columns: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
}
}])
.withOption('initComplete', function(settings) {
// Recompiling so we can bind Angular directive to the DT
$compile(angular.element('#' + settings.sTableId).contents())($scope);
})
;
从服务器返回的数据格式为:
data:(9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
draw:1
message:null
recordsFiltered:100
recordsTotal:100
success:true
我正在使用数据表版本: * angular-datatables - v0.5.6 * https://github.com/l-lin/angular-datatables
angular js version:1.5.6