json - AngularJS multidimensional Array -
i have following 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 } ] } ] }
and i'm trying output each "ownerid", each "lat" , "long" associated ownerid. i'm using following:
var app = angular.module('myapp', []); app.controller('customersctrl', function($scope, $http) { $http.get("path json") .success(function (response) { $scope.datamodel = response.records; }); });
and (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>
it outputs ownerid's not tracks?? has idea why please? thanks...
well that's because second repeat doesn't know trackinfo is. doesn't exist @ moment of ng-repeat. have nest it. you, still have specify pointer 'tracks', or else iterate on wrong dataset. 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>
Comments
Post a Comment