使用角度js显示组值..?

时间:2015-07-15 06:29:53

标签: javascript angularjs data-binding angularjs-ng-repeat ng-repeat

现在我已经创建了这样的脚本。

$scope.newsample = { 
    1 : [
    {'SUPNAME' : 'HABIB','PKSLIP' : '17193','PRDCODE' : '52003','ITMDESG' : '2550','ITMCODE' : 'IAC1552072','iv' : '1'},
    ],
    2 : [
    {'SUPNAME' : 'EKJOT','PKSLIP' : '55414','PRDCODE' : '52236','ITMDESG' : '420','ITMCODE' : 'IBD5243688','iv' : '2'},
    {'SUPNAME' : 'EKJOT','PKSLIP' : '55414','PRDCODE' : '52236','ITMDESG' : '426','ITMCODE' : 'IBD5243661','iv' : '3'},
    {'SUPNAME' : 'EKJOT ','PKSLIP' : '55414','PRDCODE' : '52236','ITMDESG' : '428','ITMCODE' : 'IBD5243709','iv' : '4'},
    ],
    3 : [
    {'SUPNAME' : 'JAYSONS','PKSLIP' : '50225','PRDCODE' : '53554','ITMDESG' : '6089','ITMCODE' : 'IBC4745296','iv' : '5'},
    ]
}
$scope.total = [
    {'iv' : '1'},
    {'iv' : '2'},
    {'iv' : '3'},
    ]

现在我该如何以这种格式显示它。

SUPNAME:HABIB  PKSLIP:17193
ITMDESG:IAC1552072

SUPNAME:EKJOT   PKSLIP=55414
ITMDESG:IBD5243688  ITMDESG:IBD5243661 ITMDESG3:IBC4745296

SUPNAME:JAYSONS  PKSLIP:50225
ITMDESG:IBC4745296

我试过这样,但SUPNAME也在重复一些想法,我怎么能使用ng-if跳过相同的SUPNAME。我需要显示SUPNAME一次,相应的ITMDESG应以分组格式显示。

<div ng-repeat="tot_grp in total " ng-init="subval=newsample[tot_grp.iv]">
    <div ng-repeat = "grp_val in subval">
        <div>
        <label>{{{{grp_val.SUPNAME}}}}</label>
        <label>{{{{grp_val.PKSLIP}}}}</label>
        </div>
        <div style="clear:both"></div>
        <div>
        <label>{{{{grp_val.ITMDESG}}}}</label>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

您可以将$first用于内部ng-repeat

<强>标记

<div ng-repeat = "grp_val in subval">
    <div ng-if="$first">
      <label>{{grp_val.SUPNAME}}</label>
      <label>{{grp_val.PKSLIP}}</label>
    </div>
    <div style="clear:both"></div>
    <div>
    <label>{{grp_val.ITMDESG}}</label>
    </div>
</div>