2016-12-05 5 views
0

大きなjsonファイルがあり、AngularJSを使用してファイル名を抽出しようとしています。毎年ng-repeatを使用してファイル名を抽出するにはどうすればよいですか?ここで私はこのコントローラを作成する方法を確認していないPlunkerng-repeatを使用してjsonからファイル名を抽出します。

App.controller('TodoCtrl', function($scope, $http) { 
    $http.get('data.json') 
     .then(function(res){ 
      $scope.todos = res.data;     
     }); 
    }); 

の私の簡単な例です。

答えて

0

あなたは(キー、値)のペアとしてそれらにアクセスすることができ

App.controller('TodoCtrl', function($scope, $http) { 
    $http.get('data.json') 
     .then(function(res){ 
      $scope.todos = res.data[2015];   
     }); 
}); 

DEMO

0

、キーの値によって項目を単にアクセスすることができます。

HTML

<ul> 
    <li ng-repeat="(year,files) in todos" ng-click="sendData(year,files)"> 
     {{year}}:{{files}} --- click here 
    </li> 
    </ul> 

DEMO

を見てください
関連する問題