AngularJS多维数组 [英] AngularJS multidimensional Array

查看:94
本文介绍了AngularJS多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON:

{
   "records":[
      {
         "TrackID":"4",
         "ownerID":"14",
         "name":"Test1",
         "minTime":"2015-04-08T16:50:51Z",
         "maxTime":"2015-04-08T17:26:39Z",
         "tracks":[
            {
               "lat":"53.3996905",
               "long":"-2.92532816666667",
               "time":"2015-04-20T06:34:46Z",
               "hour":6
            },
            {
               "lat":"53.3997495",
               "long":"-2.92545483333333",
               "time":"2015-04-20T06:35:01Z",
               "hour":6
            },
            {
               "lat":"53.4008018333333",
               "long":"-2.9253085",
               "time":"2015-04-20T06:35:13Z",
               "hour":6
            }
         ]
      }
   ]
}

,并且我尝试输出每个与ownerID关联的"ownerID",然后输出每个"lat"和"long".我正在使用以下内容:

and I'm trying to output each "ownerID", then each "lat" and "long" associated with the ownerID. I'm using the following:

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
   $http.get("path to json")
   .success(function (response) {
       $scope.dataModel = response.records;
       });
});

然后是(HTML)

<div ng-app="myApp" ng-controller="customersCtrl">

<table>
  <tr ng-repeat="trackInfo in dataModel">
    <td>
    {{ trackInfo.ownerID}}
    </td>
  </tr>

  <tr ng-repeat="trackDetails in trackInfo">
    <td>
    {{ trackDetails.lat }}
    </td>
  </tr>

</table>

</div>

它输出所有者ID,但不输出曲目??有谁知道为什么要吗?谢谢...

It outputs the ownerID's but not the tracks?? Has anyone any idea why please? Thanks...

推荐答案

好吧,这是因为您的第二次重复不知道什么是trackInfo.它只是在ng-repeat时不存在.您必须将其嵌套.但是然后,您仍然必须指定指向轨道"的指针,否则您将遍历错误的数据集.这应该起作用:

Well that's because your second repeat doesn't know what trackInfo is. It just doesn't exist at the moment of ng-repeat. You have to nest it. But then you, still have to specify pointer to 'tracks', or else you will iterate over wrong dataset. This should work:

<table>
  <tr ng-repeat="trackInfo in dataModel">
    <td>
    {{ trackInfo.ownerID}}
    </td>
    <td ng-repeat="trackDetails in trackInfo.tracks">
    {{ trackDetails.lat }}
    </td>
  </tr>  
</table>

这篇关于AngularJS多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆