如何分组和显示角度js中的值

时间:2015-07-14 05:52:04

标签: javascript angularjs

我已经创建了像这样的范围函数

$scope.sample = [
   {'SUPNAME':'AAA','SUPCODE':'22671','SLIPNO':'18384','DESG':'1','iv':'1'},
   {'SUPNAME':'AAA','SUPCODE':'22671','SLIPNO':'18384','DESG':'2','iv':'2'},
   {'SUPNAME':'AAA','SUPCODE':'22671','SLIPNO':'18384','DESG':'3','iv':'3'},
   {'SUPNAME':'BBB','SUPCODE':'24603','SLIPNO':'26714','DESG':'1','iv':'4'},
   {'SUPNAME':'BBB','SUPCODE':'24603','SLIPNO':'26714','DESG':'2','iv':'5'},
   {'SUPNAME':'BBB','SUPCODE':'24603','SLIPNO':'26714','DESG':'3','iv':'6'},
]

我必须通过分组显示相同的SUPNAME,SUPCODE,SLIPNO。例如,我必须像这样显示它。

SUPNAME:AAA  SUPCODE=22671
DESG 1  DESG2 DESG 3


SUPNAME:BBB   SUPCODE=24603
DESG 1  DESG2 DESG 3

那么我怎样才能为此创建ng-repeat ..给出一些解决方案。

1 个答案:

答案 0 :(得分:2)

我试图为你的案例创建一个Codepen

grouped Codepen

<table  class="table table-striped">
<tr><td>{{data1}}</td><td>{{data2}}</td></tr>
<tr ng-repeat="item in filteredsample = (sample | filter:{ SUPNAME: 'AAA'})">
</tr>
  <ul ng-repeat="thing in filteredsample">
<li style = "float:left; margin:20px">DESG VALUE {{$index}} = {{thing.DESG}}</li>
</ul>
</div>

希望这有帮助