2015-07-11 47 views
1

我有一個過濾器應用在下拉菜單上,但我希望根據另一個下拉值刪除它。下面的代碼。如果用戶選擇「中等」(或任何其他值),那麼我需要刪除在用戶選擇「小」時應用的過濾器。現在,如果用戶選擇「小」,然後選擇「中」,則選項仍然被濾除。AngularJS - 停留在刪除/清除過濾器

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; 
} 
+0

檢查了這一點:http://stackoverflow.com/questions/29738014/making-an-angular-filter-conditional我不知道回答你的問題,但是這看起來就像你想要的一樣。 – VSO

+0

謝謝你的信息! – JD06

回答

1

創建一個角色$過濾器,它將顏色和大小作爲參數。

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

+0

這非常有幫助!謝謝! :-) – JD06