分页对吴-表加载JSON数据后不工作分页、加载、数据、工作

2023-09-13 03:12:02 作者:唯有努力

我也跟着在 http://bazalt-cms.com/为分页,但​​使用 $ http.get 而不是硬编码在控制器的一个变量。

I followed the example on http://bazalt-cms.com/ for the pagination but using $http.get instead of hard-coding a variable in the controller.

  $http.get("data.json").success(function(data){
       $scope.dataset = data;
   }

我也感动了 $ scope.tableParams 中的 $ http.get

$http.get("data.json").success(function(data){
     $scope.dataset = data;

     $scope.tableParams = new ngTableParams({
      ...
    }
});

和改变了数据变量 $ scope.dataset

total: $scope.dataset.length, // length of data
getData: function($defer, params) {
        $defer.resolve($scope.dataset.slice((params.page() - 1) * params.count(), params.page() * params.count()));}

一切工作正常,除了分页现在不工作这里见Plnkr

推荐答案

我一直在 NG-表工作了一段时间。当我试图用比 $数据等变量名数据,它似乎并没有工作。因此,我建议你应该坚持使用 $数据数据而不是任何其他变量的名称,如数据集

I've been working with ng-table for a while. When I tried using variable names other than $data or data, it doesn't seem to work. So I suggest you should stick to using $data or data instead of any other variable names like dataset.

下面是一个工作 Plunker 。

Here's a working Plunker.

更新

看起来像我错过了,看看是什么在OP的问题真的错了。由于的泰勒科利尔的和的尤纳斯黑热病的在评论中提到的,你只需要使用 $数据< TR NG重复=用户在$数据> 而不是< TR NG重复=用户数据> 。而且,如果你在你的控制器code使用数据没关系。

Looks like I missed to see what was really wrong in the OP's question. As Tyler Collier and yunus kala mentioned in the comments, you just have to use $data like <tr ng-repeat="user in $data"> instead of <tr ng-repeat="user in dataset">. And it doesn't matter if you use data or dataset in your controller code.