我需要使用angularjs数据表来显示从API获取的JSON数据,但是我的JSON具有子对象,因此无法将此数据获取到表中。 这是我的json
{
"1009": {
"id": 1009,
"serial_number": "1009-U",
"campaigns": {
"52": {
"id": 52,
"name": "testSLOV"
},
"47": {
"id": 47,
"name": "IMA PODJELE"
},
"44": {
"id": 44,
"name": "TEST DUPLO"
},
"30": {
"id": 30,
"name": "ag3"
},
"26": {
"id": 26,
"name": "fdgdfsg"
}
}
},
"1051": {
"id": 1051,
"serial_number": "1051-U",
"campaigns": {
"52": {
"id": 52,
"name": "testSLOV"
},
"43": {
"id": 43,
"name": "test weather"
},
"39": {
"id": 39,
"name": "default2"
},
"37": {
"id": 37,
"name": "ag5"
}
}
},
"1500": {
"id": 1500,
"serial_number": "1500-U",
"campaigns": {
"51": {
"id": 51,
"name": "ag10"
}
}
}
}
这是我的ctrl
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
url: 'url',
type: 'GET'
})
.withDataProp('data')
.withOption('processing', true)
.withOption('responsive', true)
.withPaginationType('full_numbers')
vm.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('Id'),
DTColumnBuilder.newColumn('type').withTitle($translate('TYPE')),
DTColumnBuilder.newColumn('city').withTitle($translate('CITY')),
]
我尝试将其添加到ajax中,
dataSrc: function ( d ) {
angular.forEach(d, function(k, v){
console.log(k);
return k;
})
},
在控制台中,我获取数据,但不知道如何在视图中将数据从子级获取到表中。
这里是htm
<table datatable="" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" class="row-border hover" width="100%"></table>
我也尝试在newColumn中添加data.id,但没有任何反应。
DTColumnBuilder.newColumn('data.id').withTitle('Id'),
我在控制台中出现错误
jquery.dataTables.min.js:48未捕获的TypeError:无法读取未定义的属性'length'