使用json数据进行ng-repeat

时间:2015-08-11 12:01:43

标签: json angularjs

我在postgres数据库的json列中保存了以下json数据

trunc( max( cssh.change_date ))

我尝试通过ng-repeat来获取它,但我不知道如何。

我尝试使用以下代码

{
  "runway": [
    {"number":"13R/13L", "length":"14511", "lengthuom":"ft"},
    {"number":"10R/15L", "length":"98641", "lengthuom":"ft"}, 
    {"number":"16R/22L", "length":"65410", "lengthuom":"ft"} 
  ]
}

有人可以帮助我在表格中显示这些数据吗?

3 个答案:

答案 0 :(得分:1)

从数据库获取数据并将其存储在$scope变量中。类似的东西:

$scope.assetb = {
  "runway": [
    {"number":"13R/13L", "length":"14511", "lengthuom":"ft"},
    {"number":"10R/15L", "length":"98641", "lengthuom":"ft"}, 
    {"number":"16R/22L", "length":"65410", "lengthuom":"ft"} 
  ]
};

由于ng-repeat需要一个数组,因此请修改HTML:

<tr ng-repeat="ass in assetb.runway track by $index">
   <td>{{ass.number}}</td>
</tr> 

答案 1 :(得分:1)

查看这可能会对您有所帮助: -

&#13;
&#13;
function MyController($scope){
  var data = {"runway":[ {"number":"13R/13L", "length":"14511", "lengthuom":"ft"},
 {"number":"10R/15L", "length":"98641", "lengthuom":"ft"}, 
 {"number":"16R/22L", "length":"65410", "lengthuom":"ft"} ]}
  
  $scope.list = data.runway;
 } 
&#13;
<html ng-app>
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
</head>
<body>
<div ng-controller="MyController">
  <p ng-repeat="l in list track by $index">{{l.number}}</p>
</div>  
</body>
</html>  
&#13;
&#13;
&#13;

答案 2 :(得分:1)

按$ index删除直线曲目并使用

<tr ng-repeat="ass in assetb.runway">
     <td>{{ass.number}}</td>
</tr> 

Fiddle