Angularjs 按日期对服务器中的json数据进行分组
我正在以下面的格式从我的服务器检索数据Angularjs 按日期对服务器中的json数据进行分组,angularjs,ionic-framework,Angularjs,Ionic Framework,我正在以下面的格式从我的服务器检索数据 [{id: 1, title:"hello world", date:"2014-10-11",location: "The Room"},{id: 1, title:"hello world2", date:"2014-10-11",location: "The Room"}, {id: 1, title:"hello world3", date:"2014-10-11",location: "The Room"}] 我试图在我的视图中这样显示数据
[{id: 1, title:"hello world", date:"2014-10-11",location: "The Room"},{id: 1, title:"hello world2", date:"2014-10-11",location: "The Room"}, {id: 1, title:"hello world3", date:"2014-10-11",location: "The Room"}]
我试图在我的视图中这样显示数据
- 2014-10-11
- 你好,世界
- 你好,世界2
- 你好,世界3
- 2014-10-11
- 你好,世界
- 你好,世界2
- 你好,世界3
- 2014-10-11
- 你好,世界
- 你好,世界2
- 你好,世界3
- 2014-10-11
- 你好,世界
- 你好,世界2
- 你好,世界3
<script type="text/ng-template" id="schedule.html">
<ion-view title="Schedule">
<ion-content>
<ion-list ng-repeat="date in datesToFilter() | filter:filterDates">
<div class="item item-divider">{{ date.date }}</div>
<ion-item href="#/tab/schedule/{{event.id}}" class="event item-icon-right" ng-repeat="event in events | filter:{date: date.date}">
<span class="time">{{ event.startstamp }}</span>
<span class="title">{{ event.title }}</span>
<i class="icon ion-chevron-right"></i>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
</script>
ng repeat中的循环可能有问题。你能展示你的代码吗?使用你发布的数据,这就可以了。所以问题一定在代码中的某个地方。@CaspNZ谢谢你的提示,我的循环中有个问题
function($rootScope, $scope, $q, API, $data, $window) {
$scope.events = $data.events;
var indexedDates = [];
$scope.datesToFilter = function() {
indexedDates = [];
return $scope.events;
}
$scope.filterDates = function(event) {
var isNew = indexedDates.indexOf(event.date) == -1;
if (isNew) {
indexedDates.push(event.date);
}
return isNew;
}