angularjs – 带有ng-repeat的角度列表,日期为分隔符

前端之家收集整理的这篇文章主要介绍了angularjs – 带有ng-repeat的角度列表,日期为分隔符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个JSON对象,其中包含不同的事件,如下所示:
  1. {
  2. "error":false,"events":[
  3. {
  4. "id":1,"title":"First entry","date":"2014-11-04"
  5. },{
  6. "id":2,"title":"Second entry",{
  7. "id":3,"title":"Third entry","date":"2014-11-05"
  8. },{
  9. "id":4,"title":"Fourth entry","date":"2014-11-06"
  10. },{
  11. "id":5,"title":"Fifth entry","date":"2014-11-06"
  12. }
  13. ]
  14. }

该对象存储在我的控制器的$scope.events中.

现在我循环这个数组来构建事件列表:

  1. <ion-list>
  2. <div class="item item-divider">
  3. {{event.date}}
  4. </div>
  5. <a class="item item-thumbnail-left" href="#/app/event/{{event.id}}" ng-repeat="event in events">
  6. <img src="media/thumbnails/{{event.id}}.jpg">
  7. <h1>{{event.title}}</h1>
  8. </a>
  9. </ion-list>

我的目标是每天只将{{event.date}}显示为列表分隔符一次.所以在这个考试中,它看起来像这样:

2014-11-04(分频器)

>第一次进入
>第二次入境

2014-11-05(分频器)

>第三次进入

2014-11-06(分频器)

>第四次进入
>第五次入境

我非常喜欢离子和放大器角度,我不知道如何实现这一目标.可能有一些自定义过滤器?

总而言之,我正在寻找类似于Angular: Getting list with ng-repeat with dividers / separators的东西,但日期为分隔符而不是首字母.

一些想法?

任何帮助/提示真的很感激!

您可以使用angular.filters( https://github.com/a8m/angular-filter)按日期对列表进行分组,请参阅下面的演示
  1. var app = angular.module('app',['angular.filter']);
  2.  
  3. app.controller('homeCtrl',function($scope) {
  4.  
  5. $scope.data = {
  6. "error": false,"events": [{
  7. "id": 1,"title": "First entry","date": "2014-11-04"
  8. },{
  9. "id": 2,"title": "Second entry",{
  10. "id": 3,"title": "Third entry","date": "2014-11-05"
  11. },{
  12. "id": 4,"title": "Fourth entry","date": "2014-11-06"
  13. },{
  14. "id": 5,"title": "Fifth entry","date": "2014-11-06"
  15. }]
  16. }
  17.  
  18.  
  19. });
  1. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
  2.  
  3. <script src="//cdnjs.cloudflare.com/ajax/libs/angular-filter/0.4.9/angular-filter.min.js"></script>
  4.  
  5. <div ng-app="app">
  6. <div ng-controller="homeCtrl">
  7.  
  8. <ion-list ng-repeat="(key,value) in data.events | groupBy: 'date'">
  9. <div class="item item-divider">
  10. <h1> {{key}}</h1>
  11. </div>
  12.  
  13. <a class="item item-thumbnail-left" href="#/app/event/{{event.id}}" ng-repeat="event in value">
  14. <img src="media/thumbnails/{{event.id}}.jpg">
  15. <h3>{{event.title}}</h3>
  16. </a>
  17. </ion-list>
  18.  
  19.  
  20. </div>

猜你在找的Angularjs相关文章