2017-01-11 3 views
0

나는 다음과 같은 코드를 가지고 :각도 필터

<select name="condition" 
    ng-options="operation.id as operation.description for operation in Operators | myfilter:criterion_id" > 
</select> 

내가 누구 operation.idcriterion_id에 해당하는 옵션을 내 선택 목록을 채우려

module.filter('myfilter', function() { 
    return function (x) { 
    return ????? 
    }; 
}); 

. 어떻게하면 될까요?

답변

1

조건에 따라 배열을 필터링하고 필터링 된 배열을 반환해야합니다.

module.filter('myfilter', function() { 
    return function (arrayOptions, criterion_id) { 
    var result = []; 
    result = arrayOptions.filter(function(operation){ 
     return (operation.id == criterion_id); 
    }) 
    return result; 
    }; 
}); 

하지만 당신은 그렇지 않으면 각도에서 필터 filter를 사용해야합니다, 데이터 조작과 복잡한 필터링 프로세스의 경우에는이 작업을 수행해야합니다.

Operators | filter: {id: criterion_id} 
2
당신은 filter이 작동 자신의 필터, 각도의 기본을 할 필요가 없습니다

: 난 그냥 여기에 몇 가지 코드를 작성했습니다

<select name="condition" 
    ng-options="operation.id as operation.description for operation in Operators | filter:{id:criterion_id}" > 
</select> 
0

는 .. 그것을 확인하십시오 : http://jsfiddle.net/k86sy0ku/1/

<select 
     ng-options="p as p.first for p in people | filter:{id:FilterId}" 
     ng-model="selectedPerson"></select>