我有一组显示的对象,其中包含有关该对象的信息。我使用ng-repeat来显示所有对象,但我现在想要实现一个过滤器或函数,按月分组对象,如果我有同月注册的对象,则在我的索引中显示该月的所有对象
这是我的JSON数组,值“upload_date”是我想获得特定月份的地方
"_embedded": {
"incidents": [
{
"id": 20,
"name": "Nombre de incidente",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"timestamp": "2015-03-13T00:00:00-0600",
"upload_date": "2015-03-31T23:58:19-0600",
"archived": false,
"_links": {
"self": {
"href": "http://incidents-core/app_dev.php/incidents/20"
},
"attachments": {
"href": "http://incidents-core/app_dev.php/incidents/20/attachments"
},
"comments": {
"href": "http://incidents-core/app_dev.php/incidents/20/comments"
}
}
这是我的带有ng-repeat的html代码,这可行
<ul class="list" >
<h1>January</h1><br />**<---- HERE I WOULD LIKE THO SHOW THE MONTH**
<br />
<li class="list__item" ng-repeat="incident in incidents">
<!-- ngrepeat: mostrar total de incidentes-->
<a href="#" data-toggle="modal" data-target="#incidentModal" ng-click="selectIncident($index)">
<!-- /.badgetSection-->
<figure class="list__item__inner">
<div class="bagdets">
<span class="glyphicon glyphicon glyphicon-comment"><span> {{incident._embedded.commentsCount}} </span>
<span class="glyphicon glyphicon glyphicon-picture"><span> {{incident._embedded.attachmentsCount}} </span>
</div>
<!-- ./badges -->
<div class="incident-image">
<img ng-src="{{incident._links.thumbnail.href || 'img/03.jpg'}}">
<p class="incident-type"><span>{{incident._embedded.incident_type}}</span>
</p>
</div>
<figcaption>
<p>{{incident.name}}</p>
<div class="line-separator"></div>
<p>{{incident.description | strLimit: 90 }}</p>
<div class="line-separator"></div>
<p><span class="glyphicon glyphicon-calendar"></span> {{incident.timestamp | date:'EEE - dd/mm/yyyy'}} <span class="glyphicon glyphicon-time"></span> {{incident.timestamp | date:'hh:mm:ss a'}}</p>
<div class="line-separator"></div>
<p> <span class="glyphicon glyphicon-user"></span> {{incident._embedded.employee}}</p>
</figcaption>
</figure>
</a>
</li>
</ul>
我的想法是尝试显示按月排序的所有已注册对象,如果该月没有对象,则不显示月份。但我不知道如何按月分组
答案 0 :(得分:1)
检查这个角度过滤器,它提供了很多选项 https://github.com/a8m/angular-filter
答案 1 :(得分:0)
What your are looking for is to perform an automatic list divider.
See that nice exemple for more information : http://mcgivery.com/dividing-list-automatically-ionic-framework/