Angularjs filtering with checkboxes

最后都变了- 提交于 2020-01-06 20:17:40

问题


I have seen this jsfiddle of how to create a nice toggling filter using checkboxes:

http://jsfiddle.net/ExpertSystem/wYfs4/3/

Full credit to Stack Overflow user ExpertSystem for this jsfiddle (is there any way to send direct messages to other users? Or tag them in this post?)

I would like to know how this code could be edited so that when a checkbox is selected, it removes the relevant items from the display (as opposed to only displaying the relevant items).

So at present when you check the "red" checkbox you will see displayed:

Wine A (red)
Wine B (red)
Wine D (red)
Wine E (red)

But what I want to see is:

wine C (white)
wine F (white)
wine G (champagne)
wine H (champagne)

So essentially I'm looking to reverse the filter. I have played around a little bit, but have had no luck so far and I'm not really sure how to go about it.


回答1:


easy peasy lemon squeezy :) just change the condition, check the Fiddle

$scope.filterByCategory = function (wine) {
    console.log($scope.filter);
    return !$scope.filter[wine.category];
};


来源:https://stackoverflow.com/questions/35222734/angularjs-filtering-with-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!