gpt4 book ai didi

angularjs - 如何使用复选框在 angularJS 中过滤多个值(或运算)

转载 作者:行者123 更新时间:2023-12-02 22:13:11 25 4
gpt4 key购买 nike

如何在 angularJS 中使用 Checkbox 过滤多个值(OR 运算)

<ul ng-repeat="movie in movies |filter:Filter.Comedy | filter:Filter.Action  | filter:Filter.Drama">
<li>{{movie.name}}</li>
</ul>
<label>Comedy</label><input type="checkbox" ng-model="Filter.Comedy" ng-true-value="Comedy" data-ng-false-value=''/><br/>
<label>Action</label><input type="checkbox" ng-model="Filter.Action" ng-true-value="Action" data-ng-false-value=''/><br/>
<label>Drama</label><input type="checkbox" ng-model="Filter.Drama" ng-true-value="Drama" data-ng-false-value=''/>

http://jsfiddle.net/samibel/va2bE/1/

最佳答案

使用过滤功能:

查看:

<ul ng-repeat="movie in movies | filter: showMovie">
<li>{{movie.name}}</li>
</ul>

Controller :

$scope.showMovie = function(movie){
return movie.genre === $scope.Filter.Comedy ||
movie.genre === $scope.Filter.Drama ||
movie.genre === $scope.Filter.Action;
};

Fiddle

关于angularjs - 如何使用复选框在 angularJS 中过滤多个值(或运算),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21411686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com