是否可以使用复选框删除筛选器?
如果选中复选框,将禁用ng-重复中的筛选器.例如,如果选中复选框countryfilter和,则相关筛选器将被禁用。
原始代码(启用过滤器)
<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>(禁用复选框的筛选器、winetypefilter和countryfilter )将产生以下结果:
<li ng-repeat="wine in wines | stylefilter:styletypes">
{{wine.name}} is a {{wine.type}} with {{wine.style}} style from {{wine.country}}
</li>发布于 2014-06-08 21:30:25
当然,您可以动态禁用过滤器.有很多方法可以做到这一点,我认为最简单的解决方案就是把第三个参数作为布尔值来检查过滤器是否启用.
这是过滤器样本..。
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
}
};
});这是柱塞..。
https://stackoverflow.com/questions/24110189
复制相似问题