以角度js表格式显示jsonArray

时间:2016-07-13 10:25:48

标签: angularjs arrays dynamic

我收到的回复数据为:

array=[{"job id":"1",
        "level 1":"er",
        "level 2":"ED",
        "level 3":"MT",
        "status":"mt"
       },
      {"job id":"2",
       "level 1":"ear",
       "level 2":"ED",
       "level 3":"MT",
       "status":"mt"}
     ]

在上面的数组中,有两个从数据库中检索的记录,它可能会有相应的变化。

我希望以表格格式表示,列必须是作业ID,级别1,级别2等,以及值1,ed等,如在角度JS中。

1 个答案:

答案 0 :(得分:0)

尝试在(key,value)

中使用ng-repeat

var app=angular.module('app',[])
app.controller("Ctrl",function($scope,$filter){
   $scope.array=[
          {"job id":"1","level 1":"er","level 2":"ED","level 3":"MT","status":"mt"},
          {"job id":"2","level 1":"ear","level 2":"ED","level 3":"MT","status":"mt"}
     ]

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller=" Ctrl">
  <table border="1">
    <thead>
        <tr ng-repeat="(key,value) in array" ng-if="$last">
         <td ng-repeat="(key,v) in value">{{key}}</td>
      </tr>
    </thead>
       <tr ng-repeat="(key,value) in array">
         <td ng-repeat="(key,v) in value">{{v}}</td>
      </tr>
  </table>
</div>