如何使用ng-repeat值过滤ng-repeate中的数据

时间:2015-09-08 13:03:02

标签: angularjs angularjs-ng-repeat angular-filters

我需要根据ng-repeate获得的值过滤一些数据。 我的HTML看起来像这样。 我需要通过使用值

进行过滤来显示来自其他范围对象($scope.allData)的数据
<div ng-repeat="value in selectedIds">
    <h6>Id</h6>{{}} <br/>
    <h6>Name</h6>{{}} <br/>
    <h6>Age</h6>{{}} <br/>

   </div>

我的控制器看起来像

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';

  $scope.selectedIds=[{id:"123"},{id:"124"},{id:"125"},{id:"126"}];
  $scope.allData=[{id:"123",name:"James",age:"21"},
  {id:"124",name:"James",age:"21"},
  {id:"125",name:"Frank",age:"22"},
  {id:"126",name:"John",age:"24"},
  {id:"127",name:"Jimmy",age:"26"},
  {id:"128",name:"Ann",age:"61"},
  {id:"129",name:"Mark",age:"41"},
  {id:"130",name:"Lach",age:"33"}
  ];
});

I create the the plunker

1 个答案:

答案 0 :(得分:1)

您可以在ng-repeat功能中使用filter

<body ng-controller="MainCtrl">
   <div ng-repeat="value in selectedIds">
      <div ng-repeat="values in allData | filter: value.id">
         <h6>Id</h6>{{values.id}} <br/>
         <h6>Name</h6>{{values.name}} <br/>
         <h6>Age</h6>{{values.age}} <br/>
      </div>
   </div>
</body>

希望它适用于您的情况。这是工作link