如何使用JSON具有角数据表 [英] How to use this json with angular datatables
本文介绍了如何使用JSON具有角数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的服务器响应。
This is my server response.
{
"status": "success",
"data": [{
"id": null,
"reportType": "Total Voucher Report",
"reportModule": "Vouchers",
"reportData": [{
"id": "1",
"voucherPackId": "2",
"serialNumber": "0",
"status": "Free",
"isBlocked": "N",
"voucherPin": "0",
"buyDate": null,
"redeemDate": null,
"phoneNumber": null,
"statusCode": null,
"identifier": "MCM0007532",
"merchantName": "test1",
"voucherName": "fddf",
"expiryDate": "2016-02-24 00:00:00",
"dealCategory": "Hotels \u0026 Travel",
"shortDescription": "xvxv",
"voucherWorth": "33.00"
}, {
"id": "2",
"voucherPackId": "2",
"serialNumber": "0",
"status": "Free",
"isBlocked": "N",
"voucherPin": "0",
"buyDate": null,
"redeemDate": null,
"phoneNumber": null,
"statusCode": null,
"identifier": "MCM0007532",
"merchantName": "test1",
"voucherName": "fddf",
"expiryDate": "2016-02-24 00:00:00",
"dealCategory": "Hotels \u0026 Travel",
"shortDescription": "xvxv",
"voucherWorth": "33.00"
}, {
"id": "3",
"voucherPackId": "2",
"serialNumber": "0",
"status": "Free",
"isBlocked": "N",
"voucherPin": "0",
"buyDate": null,
"redeemDate": null,
"phoneNumber": null,
"statusCode": null,
"identifier": "MCM0007532",
"merchantName": "test1",
"voucherName": "fddf",
"expiryDate": "2016-02-24 00:00:00",
"dealCategory": "Hotels \u0026 Travel",
"shortDescription": "xvxv",
"voucherWorth": "33.00"
}]
}],
"message": null}
我用它作为,
vm.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', {
url: config.base_url + 'report/voucher?module=Vouchers&type=Total Voucher Report&merchant=1',
type: 'POST',
dataSrc: 'data.data[0].reportData[0]',
})
.withOption('processing', true)
.withOption('serverSide', true)
.withBootstrap()
.withPaginationType('full_numbers');
报告说,无效的JSON响应。鸭preciate你的好心帮助。
调试结果: http://debug.datatables.net/urizon
推荐答案
使用下面的值 DATASRC
选项:数据[0] .reportData code>,如下图所示。另外你需要删除
服务器端
和处理
选项,因为您的数据没有对服务器端的处理模式是正确的结构
Use the following value for dataSrc
option: data[0].reportData
as shown below. Also you need to remove serverSide
and processing
options since your data doesn't have correct structure for server-side processing mode.
您还需要定义列结构,因为你正在使用对象数组作为数据源。
You also need to define columns structure since you're using array of objects as your data source.
vm.dtOptions = DTOptionsBuilder
.newOptions()
.withOption('ajax', {
url: config.base_url + 'report/voucher?module=Vouchers&type=Total Voucher Report&merchant=1',
type: 'POST',
dataSrc: 'data[0].reportData'
})
.withBootstrap()
.withPaginationType('full_numbers');
vm.dtColumns = [
/* List data properties for each column in the table. */
DTColumnBuilder.newColumn('id'),
DTColumnBuilder.newColumn('voucherPackId'),
DTColumnBuilder.newColumn('serialNumber'),
DTColumnBuilder.newColumn('status')
];
这篇关于如何使用JSON具有角数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文