2015-09-08 65 views
0

我需要根據從ng-repeate獲得的值過濾一些數據。 我的html看起來像這樣。 我需要使用值如何使用ng-repeat值過濾ng-repeate中的數據

<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

,你可以在你的NG使用filter過濾,顯示其他範圍對象($scope.allData)數據重複功能。

<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

相關問題