Reputation: 5226
I have the next map:
{
1: [
"John": 123,
"Doe": 234
],
2: [
"John": 456,
"Doe": 345
]
//and so on...
}
I have to display them with ng-repeat sorted by index and then with inner ng-repeat sorted by value:
- 2
- Doe 234
- John 123
- 1
- John 456
- Doe 345
I tried to find the solution but didn't find anyting.
Upvotes: 0
Views: 358
Reputation: 2171
It's easy to order by key when you use angular-underscore
<div ng-repeat="item in pairs(obj) | orderBy:first:true"> Key: {{ item[0] }}; Value: {{item[1]}}</div>
In your case it can look like this:
HTML:
<ul ng-repeat="obj in pairs(data) | orderBy:first:true">
<li>{{ obj[0] }}</li>
<ul ng-repeat="item in pairs(obj[1]) | orderBy:last:true">
<li> {{ item[0] }} {{item[1]}}</li>
</ul>
</ul>
JS:
$scope.data = {
1:{
'John':123,
'Doe':234
},
2:{
'John':456,
'Doe':345
}};
See working Plunker with your case
To reverse order just change orderBy:first:true
to orderBy:first:false
.
Upvotes: 1