체크 박스를 사용하여 필터를 제거 할 수 있습니까?
확인란을 선택하면 ng-repeat 내부의 필터가 비활성화됩니다. 체크 박스의 경우 예를 들어, countryfilter 및 winetypefilter이 선택되어, 관련 필터를 사용할 수있을 것이다.
원본 코드 (필터 활성화 됨)
<li ng-repeat="wine in wines | winetypefilter:winetypes| countryfilter:countrytypes | stylefilter:styletypes">
{{wine.name}} is a {{wine.type}} with {{wine.style}} style from {{wine.country}}
</li>
(필터는 체크 박스로 사용할 수 countryfilter 및 winetypefilter 초래)
<li ng-repeat="wine in wines | stylefilter:styletypes">
{{wine.name}} is a {{wine.type}} with {{wine.style}} style from {{wine.country}}
</li>
물론 필터 비활성화를 동적으로 활성화 할 수 있습니다 ... 내 마음에 오는 가장 간단한 해결책은 필터가 활성화되었는지 여부를 확인하기 위해 부울로 세 번째 매개 변수를 보내는 것입니다.
여기 필터 샘플입니다 ...
app.filter('winetypefilter', function () {
return function(input, filter, isEnable) {
// if isEnable then filter out wines
if (isEnable) {
var result = [];
angular.forEach(input, function (wine) {
angular.forEach(filter, function (isfiltered, type) {
if (isfiltered && type === wine.type) {
result.push(wine);
}
});
});
return result;
}
// otherwise just do not any filter just send input without changes
else{
return input
}
};
});
그리고 여기 PLUNKER입니다 ...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다