我正在尝试显示按地址分组的信息。由于某种原因,orderBy和groupBy无法正常工作。
这是我的观点:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"> </script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="item in data | orderBy:'address' | groupBy:'address' " >
<h5 ng-click="toggle_visibility(item);">{{item.address}}</h5>
<div ng-hide="item.hideAddress">
<ul>
<li>First Name: {{item.firstname}} </li>
</ul>
</div>
</div>
</div>
这是我的控制者:
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.data = [
{
firstname: "user",
address: "address1",
},
{
firstname: "user1",
address: "address1",
},
{
firstname: "user2",
address: "address3",
}
];
$scope.toggle_visibility = function(item){
item.hideAddress = !item.hideAddress;
}
})
当我添加groupBy并运行它时,我根本没有显示任何数据,但是如果我删除groupBy,我将按地址获取组,但是2组具有相同的地址名称。我该怎么办呢?