我正在尝试使用ng-repeat显示列表,但我无法弄清楚如何对其进行分组。这是我的json:
{
"id": "1",
"name": "Andre Nascimento",
"client": "Lojas Mais"
},
{
"id": "1",
"name": "Andre Nascimento",
"client": "Fe comercio"
},
{
"id": "1",
"name": "Andre Nascimento",
"client": "Transtour"
},
{
"id": "2",
"name": "Carla Prata",
"client": "Fe comercio"
},
{
"id": "2",
"name": "Carla Prata",
"client": "Transtour"
}
我想得到以下结果
Andre Nascimento
*Lojas Mais
*Fe comercio
*Transtour
Carla Prata
*Fe comercio
*Transtour
答案 0 :(得分:2)
您可以按angular.filter答案中的说明使用this模块。然后你会有像
这样的东西<ul ng-repeat="(key, value) in yourArray| groupBy: 'client'">
Group name: {{ key }}
<li ng-repeat="element in value">
player: {{ element.name }}
</li>
</ul>
这应该这样做。
here there is a fiddle