【问题标题】:AngularJS - stuck on removing/clearing a filterAngularJS - 坚持删除/清除过滤器
【发布时间】:2015-07-12 09:33:39
【问题描述】:

我在下拉列表中应用了一个过滤器,但我希望根据另一个下拉值删除它。代码如下。如果用户选择“中”(或任何其他值),那么我需要删除在用户选择“小”时应用的过滤器。现在,如果用户选择“Small”然后选择“Medium”,这些选项仍然会被过滤掉。

if(val == "Small"){
 $scope.Variant.Specs.Color.Options = $scope.Variant.Specs.Color.Options.filter(function(item) {
  return item.Value !== 'Red' && item.Value !== 'Blue';
 });
}
else if(val == "Medium") {
 $scope.Variant.Specs.Color.Options = $scope.Variant.Specs.Color.Options;
}

【问题讨论】:

标签: angularjs


【解决方案1】:

创建一个以颜色和大小为参数的角度 $filter。

app.filter('filterColors', function() {
    return function(colors, size) {
        if(size=='Medium') {
            return colors;
        } else {
            return colors.filter(function(d) {
                return d != 'Red' && d != 'Blue';
            });
        }
    }
});

plunkr

【讨论】:

  • 这很有帮助!谢谢! :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-26
相关资源
最近更新 更多