按键重复的角度顺序

时间:2016-06-06 02:57:30

标签: angularjs angularjs-ng-repeat ng-repeat

我有下一张地图:

{
    1: [
        "John": 123,
        "Doe": 234 
    ],
    2: [
        "John": 456,
        "Doe": 345   
    ]
    //and so on...
}

我必须用ng-repeat按索引排序,然后用内部ng-repeat按值排序:

  
      
  • 2      
        
    • Doe 234
    •   
    • John 123
    •   
  •   
  • 1      
        
    • John 456
    •   
    • Doe 345
    •   
  •   

我试图找到解决方案,但没有发现任何问题。

1 个答案:

答案 0 :(得分:1)

使用angular-underscore

时,按键轻松订购
<div ng-repeat="item in pairs(obj) | orderBy:first:true"> Key: {{ item[0] }}; Value: {{item[1]}}</div>

在您的情况下,它看起来像这样:

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
    }};

请参阅working Plunker with your case

要撤消订单,只需将orderBy:first:true更改为orderBy:first:false

相关问题