AngularJS 数据表显示 Table 中没有可用数据
AngularJS Datatable Showing No Data Available in Table
好的,所以我是 AngularJS 的新手,但对编码并不陌生。在大多数情况下,我已经理解了 Angular 的所有内容,但在过去的几天里我一直被困在一件事上,我一直在努力。希望你们中的一位能告诉我我做错了什么。
我正在使用 AngularJS 和 Jquery Datatables。从控制器加载的数据很好,甚至显示为一行,但是它在 Jquery 框上方...在 Jquery 框内,它告诉我 "No Data Available" 它还显示显示 0 到0 个条目中的 0 个,即使应显示 1 行。
这是 HTML 与 table 的对比:
<table ng-if="ConductorTypes" class="table table-striped table-hover" datatable-setup id="ConductorTypes" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="conductorType in ConductorTypes">
<td>
{{ conductorType.id }}
</td>
<td>
{{ conductorType.name }}
</td>
<td></td>
</tr>
</tbody>
</table>
我的控制器是这样的:
'use strict';
app.controller('ConductorTypesController', ['$scope', 'stagingService', function ($scope, stagingService) {
$scope.ConductorTypes = [];
stagingService.getConductorTypes().then(function (results) {
$scope.ConductorTypes = results.data;
}, function (error) {
alert(error.data.message);
});
}]);
现在我还设置了指令,看起来像这样:
app.directive('datatableSetup', function () {
return {
restrict: 'E, A, C',
link: function (scope, element, attrs) {
var table = element.dataTable({
"aoColumnDefs": [{
'bSortable': true,
'aTargets': [-1]
}],
"oLanguage": {
"oPaginate": {
"sPrevious": "Previous",
"sNext": "Next"
}
},
"iDisplayLength": 10,
"aLengthMenu": [
[5, 10, 25, 50, -1],
[5, 10, 25, 50, "All"]
],
"sDom": '<"dt-panelmenu testbutton"><"dt-panelmenu clearfix"Tfr>t<"dt-panelfooter clearfix"ip>',
"oTableTools": {
"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
}
});
}
}
}
);
我做错了什么?为什么这不填充 Jquery 数据 table。如果有任何帮助,我将不胜感激。
感谢@Kevin F,我最终添加了一个超时,他给了我在加载后加载它的想法。
好的,所以我是 AngularJS 的新手,但对编码并不陌生。在大多数情况下,我已经理解了 Angular 的所有内容,但在过去的几天里我一直被困在一件事上,我一直在努力。希望你们中的一位能告诉我我做错了什么。
我正在使用 AngularJS 和 Jquery Datatables。从控制器加载的数据很好,甚至显示为一行,但是它在 Jquery 框上方...在 Jquery 框内,它告诉我 "No Data Available" 它还显示显示 0 到0 个条目中的 0 个,即使应显示 1 行。
这是 HTML 与 table 的对比:
<table ng-if="ConductorTypes" class="table table-striped table-hover" datatable-setup id="ConductorTypes" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="conductorType in ConductorTypes">
<td>
{{ conductorType.id }}
</td>
<td>
{{ conductorType.name }}
</td>
<td></td>
</tr>
</tbody>
</table>
我的控制器是这样的:
'use strict';
app.controller('ConductorTypesController', ['$scope', 'stagingService', function ($scope, stagingService) {
$scope.ConductorTypes = [];
stagingService.getConductorTypes().then(function (results) {
$scope.ConductorTypes = results.data;
}, function (error) {
alert(error.data.message);
});
}]);
现在我还设置了指令,看起来像这样:
app.directive('datatableSetup', function () {
return {
restrict: 'E, A, C',
link: function (scope, element, attrs) {
var table = element.dataTable({
"aoColumnDefs": [{
'bSortable': true,
'aTargets': [-1]
}],
"oLanguage": {
"oPaginate": {
"sPrevious": "Previous",
"sNext": "Next"
}
},
"iDisplayLength": 10,
"aLengthMenu": [
[5, 10, 25, 50, -1],
[5, 10, 25, 50, "All"]
],
"sDom": '<"dt-panelmenu testbutton"><"dt-panelmenu clearfix"Tfr>t<"dt-panelfooter clearfix"ip>',
"oTableTools": {
"sSwfPath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
}
});
}
}
}
);
我做错了什么?为什么这不填充 Jquery 数据 table。如果有任何帮助,我将不胜感激。
感谢@Kevin F,我最终添加了一个超时,他给了我在加载后加载它的想法。