【发布时间】:2014-05-25 22:33:02
【问题描述】:
我正在尝试使用 angular 和 jquery 数据表显示数据表,但到目前为止,在应用数据表函数后数据表仍为空。
我读到最好的方法是使用指令,但我无法让它工作。只有我设法让它工作是通过应用 100 毫秒的超时(超时小于 100 不起作用)
我想做的是在渲染 DOM 后应用数据表函数。我敢肯定有人已经做到了;)
userController.js
myApp.controller('UserController', ['$scope', 'User',
function ($scope, User) {
User.query(function(data) {
$scope.users = data;
}, function(errorData) {
});
}]);
datatableSetup.js
myApp.directive('datatableSetup', ['$timeout',
function ($timeout) {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
$timeout(function() {
elm.dataTable();
}, 100);
}
}
}]);
user.html
<table datatable-setup="" class="table table-bordered table-striped">
<thead>
<tr>
<th>Username</th>
<th>Roles</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>{{user.username}}</td>
<td>
<ul>
<li ng-repeat="role in user.roles">
{{role}}
</li>
</ul>
</td>
</tr>
</table>
【问题讨论】:
标签: javascript jquery angularjs jquery-datatables