ng-repeat不以表格格式显示数据

时间:2018-09-07 11:46:08

标签: angularjs jsp view angularjs-ng-repeat tabular

下面的代码段需要打印toolDTO对象(即对象数组,每个对象都有键和值对)。

<div ng-show="isResult" style="color: green;">
                    <table class="tble">
                        <thead>
                            <tr ng-repeat="(key, value) in toolDTO[0]" align="center"
                                style="background: #7e7e7e; color: #FFFFFF; font-size: small;">
                                <th><b>{{key}}</b></th>
                            </tr>
                        </thead>
                        <tbody ng-repeat="tool in toolDTO">                         
                            <tr ng-repeat="(key, value) in tool"
                                style="font-size: small;">
                                <td>{{value}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

toolDTO结构:

 [
        {
            "EMPLOYEE_NUMBER": "1234",
            "FIRST_NAME": "Ram",
            "LAST_NAME": "Rakul",
            "EMAIL": "Ram.Rakul@example.com",
            "UPDATED_BY": 5678,
            "UPDATED_DATE": "2018-01-23 17:25:42.635"
        },
        {
            "EMPLOYEE_NUMBER": "45678",
            "FIRST_NAME": "vinod",
            "LAST_NAME": "nai",
            "EMAIL": "vinto.nani@example.com",
            "UPDATED_BY": 5678,
            "UPDATED_DATE": "2018-01-12 20:38:50.191"
        },

    ]

ng重复代码将上面的数据打印如下。

      EMAIL 
      EMPLOYEE_NUMBER
      FIRST_NAME
      LAST_NAME
      UPDATED_DATE
      UPDATED_BY
     Ram.Rakul@example.com
     1234
     Ram
     Rakul
     2018-01-23 17:25:42.635
     5678

但是我需要下面的表格格式:

EMPLOYEE_NUMBER  FIRST_NAME LAST_NAME EMAIL  UPDATED_BY   UPDATED_DATE
 1234            Ram        Rakul    Ram.Rakul@example.com 5678        2018-01-23.

1 个答案:

答案 0 :(得分:5)

您必须为表头而不是thead > th重复thead > tr元素。还要对行重复tbody > td而不是tbody > tr

<div ng-show="isResult" style="color: green;">
                    <table class="tble">
                        <thead>
                            <tr align="center" style="background: #7e7e7e; color: #FFFFFF; font-size: small;">
                                <th ng-repeat="(key, value) in toolDTO[0]"><b>{{key}}</b></th>
                            </tr>
                        </thead>
                        <tbody ng-repeat="tool in toolDTO">
                            <tr style="font-size: small;">
                                <td ng-repeat="(key, value) in tool">{{value}}</td>
                            </tr>
                        </tbody>
                    </table>
</div>