2016-06-22 5 views
0

クラス別にフィルタリングして、それをHTMLパターンにプッシュする必要があります。jsonから角を付けてデータをフィルタリングする

は、ここでは、コードです:http://plnkr.co/edit/GG9EYmPlIyD4ZM0ehaq6?p=preview

の.html:

<div ng-controller="ClassController"> 
      <table> 
      <thead> 
       <tr> 
       <th>Name</th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="student in students"> 
       <td>{{ student.name }}</td> 
       </tr> 
      </tbody> 
      </table> 
    </div> 

の.js:

var app; 

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

app.controller('ClassController', [ 
    '$scope', '$http', function($scope, $http) { 
    $scope.students = []; 
    return $http.get('data.json').then(function(result) { 
     return angular.forEach(result.data, function(item) { 
     return $scope.students.push(item); 
     }); 
    }); 
    } 
]); 

あなたがここにリンク

答えて

0

.jsonファイルを見つけることができ、あなたのコントローラです。

var app; 

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

app.controller('ClassController', [ 
    '$scope', '$http', function($scope, $http) { 
    var someFilter = 'taple'; 
    $scope.students = []; 
    return $http.get('data.json').then(function(result) { 
     $scope.students = result.data.filter(function(item) { 
     return item.classroom.school.name.toLowerCase().indexOf(someFilter) > -1; 
     }) 
    }); 
    } 
]); 
+0

ありがとうございました! しかし、私は多くのクラスを持っているので、どのように私は学生のリストと特定のクラスを関連付けることができますか? –

関連する問題