orderBy和limitTo在ng-repeat孩子中

时间:2022-12-02 16:54:54

i would like to use orderBy and limitTo in array which is contain in other array so i need to use ng-repeat two times: i tried this but not working

我想在其他数组中包含的数组中使用orderBy和limitTo,所以我需要使用ng-repeat两次:我试过这个但是没有工作

       <ul ng-repeat="item in customarray | orderBy: 'first.date' | limitTo :10 track by $index">
            <div ng-repeat="first in item[1]">
                {{first.date | date}}
            </div>
       </ul>

here are my arrays

这是我的阵列

[
   {
      "date":"2015-09-29T07:12:14Z",
      "titre":"Changement date de clôture dossier Barbe Alain",
      "status":"closed",
      "tag":"maintenance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2015-09-04T09:45:20Z",
      "titre":"43325- NH DISTRIBUTION",
      "status":"closed",
      "tag":"assistance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2015-08-20T06:18:04Z",
      "titre":"TR: EURL NH DISTRIBUTION vous a envoyé un message depuis sa plateforme",
      "status":"closed",
      "tag":"assistance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2015-02-25T16:00:46Z",
      "titre":"Votre demande au support sans suite",
      "status":"closed",
      "tag":"assistance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2015-01-12T06:48:35Z",
      "titre":"Bonjour,\n\nle cabinet AUFICOM aura un stand lors du...",
      "status":"closed",
      "tag":"assistance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2014-12-18T09:48:38Z",
      "titre":"ISACOMPTA",
      "status":"closed",
      "tag":"maintenance",
      "id":660302971,
      "name":"Eugenie Martin"
   },
   {
      "date":"2014-12-15T14:08:08Z",
      "titre":"changement date de clôture",
      "status":"closed",
      "tag":"maintenance",
      "id":660302971,
      "name":"Eugenie Martin"
   }
]

[
   {
      "date":"2016-03-15T10:56:28Z",
      "titre":"ferme de la blonde",
      "status":"closed",
      "tag":"assistance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2016-03-08T13:51:57Z",
      "titre":"SCAN DOCUMENTS",
      "status":"open",
      "tag":"evolution",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2016-01-05T13:59:31Z",
      "titre":"EARL DU TROU DE L'ENFER",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-12-28T06:50:04Z",
      "titre":"15377- TR: SNC DE LA FERME DE LA BLONDE vous a envoyé un message depuis sa plateforme",
      "status":"closed",
      "tag":"assistance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-11-06T09:40:03Z",
      "titre":"GAEC DE LA VILLE (N°573)",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-11-02T16:28:05Z",
      "titre":"43325- NH DISTRIBUTION",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-06-26T11:41:57Z",
      "titre":"Dossier 411 : MUNIER Valérie",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-06-26T11:40:54Z",
      "titre":"Dossier 6072 : ROBERT Grégory",
      "status":"closed",
      "tag":"assistance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2015-01-15T08:58:07Z",
      "titre":"Demande De TJ",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   },
   {
      "date":"2014-12-17T10:26:37Z",
      "titre":"ECOLE DES CAVALIERS",
      "status":"closed",
      "tag":"maintenance",
      "id":661671741,
      "name":"Tanguy Jacob"
   }
]

An other solution would be to put all arrays together then i will be able to use only 1 time ng-repeat: but i don't know how can i do that i begin with this:

另一个解决方案是将所有阵列放在一起,然后我将只能使用1次ng-repeat:但我不知道我怎么能这样做,我从这开始:

controller.js

 var interarray = []
                            for(s=0;s<data.length;s++){

                              interarray.push(data[s]);

                            }
                            console.log(interarray);

2 个解决方案

#1


1  

Assuming your arrays are data1 and data2 , you can use concat

假设您的数组是data1和data2,您可以使用concat

$scope.allDatas = data1.concat(data2)

And you only need the field name in your orderBy

而且您只需要订单中的字段名称

http://jsfiddle.net/Lvc0u55v/3915/

#2


-1  

I finnaly manage it here what i did in my controller:

我在这里完成了我在控制器中所做的事情:

            var lastticket = [];

                      for (i=0; i<data.length; i++) {
                          for (j=0; j<data[i][1].length; j++) {

                              $scope.lastarray = lastticket.push(data[i][1][j]);
                          }
                      };
                        $scope.lastarray = lastticket;

and in my view:

在我看来:

 <ul ng-repeat="item in lastarray  | orderBy:'-date'| limitTo :10 track by $index">

                <li  class="row"><div class="col-md-2 date text-center">{{item.date | date}}</div><div class="col-md-3 date text-center"> {{item.name}}</div> <div class="col-md-5 date text-center">{{item.titre}}</div> <div class="col-md-2 date text-center">{{item.status}}</div></li>
        </ul>

What i did is that i loop 2 times in my array to get what i want then i send to my view ! ( but this is not the best solution i should have used angular.forEach)

我做的是我在我的阵列中循环2次以获得我想要的然后我发送到我的视图! (但这不是我应该使用angular.forEach的最佳解决方案)

#1


1  

Assuming your arrays are data1 and data2 , you can use concat

假设您的数组是data1和data2,您可以使用concat

$scope.allDatas = data1.concat(data2)

And you only need the field name in your orderBy

而且您只需要订单中的字段名称

http://jsfiddle.net/Lvc0u55v/3915/

#2


-1  

I finnaly manage it here what i did in my controller:

我在这里完成了我在控制器中所做的事情:

            var lastticket = [];

                      for (i=0; i<data.length; i++) {
                          for (j=0; j<data[i][1].length; j++) {

                              $scope.lastarray = lastticket.push(data[i][1][j]);
                          }
                      };
                        $scope.lastarray = lastticket;

and in my view:

在我看来:

 <ul ng-repeat="item in lastarray  | orderBy:'-date'| limitTo :10 track by $index">

                <li  class="row"><div class="col-md-2 date text-center">{{item.date | date}}</div><div class="col-md-3 date text-center"> {{item.name}}</div> <div class="col-md-5 date text-center">{{item.titre}}</div> <div class="col-md-2 date text-center">{{item.status}}</div></li>
        </ul>

What i did is that i loop 2 times in my array to get what i want then i send to my view ! ( but this is not the best solution i should have used angular.forEach)

我做的是我在我的阵列中循环2次以获得我想要的然后我发送到我的视图! (但这不是我应该使用angular.forEach的最佳解决方案)