在这个柱塞中,我有一个ngTable,它应该显示两行,而只显示标题。这个密码怎么了?
Javascript
var app = angular.module('app', ['ngTable']);
app.controller('myCtl', function($scope,$timeout,NgTableParams) {
$timeout(function() {
$scope.data = [
{ uid: 'User 1', nm: 'Name 1', ugr: 'Group 1'},
{ uid: 'User 2', nm: 'Name 2', ugr: 'Group 2'}
];
$scope.tableParams = new NgTableParams({dataset: $scope.data});
}, 1000);
$scope.toggleFilter = function (){
$scope.showFilter = !$scope.showFilter;
};
});HTML
<div ng-controller="myCtl" ng-app="app">
<a href="javascript:void(0)" ng-click="toggleFilter()">Toggle Filter</a>
<table ng-table="tableParams" show-filter="showFilter" class="table table-bordered">
<tbody>
<tr ng-repeat="u in $data">
<td title="'User ID'" filter="{ uid: 'text' }" sortable="'uid'" style="width:150px">{{ u.uid }}</td>
<td title="'Name'" filter="{ nm: 'text' }" sortable="'nm'" style="width:150px">{{ u.nm }}</td>
<td title="'Group'" filter="{ ugr: 'text'}" sortable="'ugr'" style="width:200px">{{ u.ugr }}</td>
</tr>
</tbody>
</table>
</div>发布于 2016-01-15 20:18:37
正确答案:
对不起,我的第一次回答太仓促了。我的解决方案解决了,但不正确。
真正的问题是需要将控制器中的“dataset”更改为“data”,如下所示(使用NgTable v.0.8.3):
$scope.tableParams = new NgTableParams({count: 5}, {data: $scope.data});我还添加了一个计数,否则,它会一次显示一个项目。
Plunkr:http://plnkr.co/edit/plDiFc4CCmrIf5YOeD5M?p=preview
发布于 2016-01-13 08:17:02
更新:此答案不正确,请将答案标记为“正确”.
如果您将HTML中的“$data”更改为“data”,它就会工作。
<table ng-table="tableParams" show-filter="showFilter" class="table table-bordered">
<tbody>
<tr ng-repeat="u in data">
<td title="'User ID'" filter="{ uid: 'text' }" sortable="'uid'" style="width:150px">{{ u.uid }}</td>
<td title="'Name'" filter="{ nm: 'text' }" sortable="'nm'" style="width:150px">{{ u.nm }}</td>
<td title="'Group'" filter="{ ugr: 'number'}" sortable="'ugr'" style="width:200px">{{ u.ugr }}</td>
</tr>
</tbody>
</table>见此处:http://plnkr.co/edit/WlPVGYjSshLkwbJ78xNO?p=preview
NgTable网站上的例子使用v1.0.0-beta.9,所以我猜它们可能有点过时了。
https://stackoverflow.com/questions/34682945
复制相似问题