2017-12-06 3 views
0

개체의 두 가지 속성을 표시하려고합니다. 이렇게하려면 배열의 다른 속성을 사용하여 필터링하고 있습니다. 여기에 해결책이 있지만 하나의 속성에 대해서만 작동합니다. 여기 각도로 목록을 필터링 할 때 두 개의 속성을 표시하는 방법

은 샘플 코드 나 이름뿐만 아니라 LAST_NAME뿐만 아니라 보여줄 수 있어야 할

controller.js 
$scope.people= [{name, last_name, code}, {name, last_name, code}]; 

view 
<tr ng-repeat="item in transactions | filter:search"> 
    <td>{{(people| filter : {code:item.person_code}:true)[0].name}}</td> 
</tr> 

입니다. 가능한 경우 쉼표로 구분합니다.

지금은 작동하지만 이름 만 표시하고 하나 이상의 속성을 표시하는 방법을 모르겠습니다.

이것도 가능합니까 ???

+0

: NG1 : –

+0

@PranayRana 같은 참조이 작업 Plnkr https://plnkr.co/edit/ sjUqjP74eiMnp5b4SIRq 필요에 맞습니까? – Zooly

+0

의 {{item.last_name}} – Zooly

답변

1

당신은 원하는 특성을 보여주기 위해 사용 후 filtertemp 변수에 결과를 저장한다 :

<tr ng-repeat="item in transactions | filter : search"> 
    <td ng-init='temp = (people | filter : {code:item.person_code}:true)[0]'> 
     {{temp.name}} {{temp.last_name}} 
    </td> 
</tr> 
+0

고마워요! 이 솔루션은 나를 위해 일했습니다 :) – jpavelw

0

이를 시도하십시오.

데이터 :

$scope.people= [{name:"SUN", last_name:"SS", code:"101"}, 
{name:"MOON", last_name:"MM", code:"103"},{name:"ION", 
last_name:"IO", code:"105"}]; 
$scope.transactions= [{person_code:"105"}, {person_code:"103"}]; 

필터 :

filter('pFilter',function(){ 
return function(input,trans) { 
var result =[]; 
angular.forEach(trans,function(item){ 
angular.forEach(input,function(p){ 
if(p.code == item.person_code) 
result.push(p); 
}); 
}); 
return result; 
} 
}) 

HTML : 데이터가 크고, 당신이 테이블에 더 표시하려면이 작동

<input ng-model="search"/> 
    <table> 
    <tr ng-repeat="p in people | filter:search|pFilter:transactions "> 
    <td>{{$index +1}}. {{p.name}}: {{p.last_name}}</td> 
    </tr> 
    </table> 

희망. 각 JS 내가 {{item.name}}에 같이 할 2

관련 문제