2016-06-16 2 views
0

이 코드가 있습니다각도 1.x 인 오브젝트 내부의 배열에 어떻게 액세스합니까?

<div class="list" ng-repeat="key in results"> 
    {{key.locations}} 
</div> 

JSON

[ 
     { 
     "locations": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], 
     "imgs": ["111.png", "222.png"] 
     } 
    ] 

JS 내가 루프를 원하는

.controller('ListCtrl', function($scope, $http) { 

    $http.get("js/data.json").success(function(results) { 
      $scope.results = results; 
      }); 

}) 

배열 1,2,3 ... 많은 감사 어떤 도움 물마루 ! 처음에 중첩되어

+0

다른'ng-repeat' –

+0

나는 동시에 2 개를 사용할 수 있습니까? – olivier

+0

'결과 [0] .locations'에서 키를 시도한 다음'{{key}}' –

답변

0

를 사용하여 다른 ng-repeat : 결과는 항상 1 개 값을 갖는 경우

<div class="list" ng-repeat="key in results"> 
    <div ng-repeat="location in key.locations"> 
     {{location}} 
    </div> 
</div> 

, 그냥 이렇게 :

<div class="list" ng-repeat="location in results[0].locations"> 
    {{location}} 
</div> 
0

var app = angular.module('plunker', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    
 
    var test = []; 
 
    $scope.results = [ 
 
     { 
 
     "locations": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], 
 
     "imgs": ["111.png", "222.png"] 
 
     } 
 
    ] 
 
    for (var i=0;i<$scope.results[0].locations.length;i++) 
 
    { 
 
     
 
     test.push($scope.results[0].locations[i]); 
 
    } 
 
    $scope.result = test; 
 
    
 
});
<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.2.28/angular.js" data-semver="1.2.28"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    <div class="list" ng-repeat="location in result"> 
 
     {{location}} 
 
    </div> 
 
    </body> 
 

 
</html>

임시 배열을 만들고 끊을 수 있습니다. 그 배열을 반복합니다. 스 니펫을 찾으십시오. 그리고 당신의 결과를 알려주십시오

관련 문제