我有一个棘手的问题。 如何使用多个复选框过滤scrope?
这是我的范围:
function UserListCtrl($scope, $filter) {
$scope.users =[{"user_id":"3","first_name":"Nathalie","last_name":"ABBAS DE CLAUZADE","societe_1":"Strasbourg Magazine \/ CUS Magazine","societe_2":false,"index_1":false,"index_2":false,"index_4":false,"index_5":false,"index_6":false,"index_7":false,"index_8":false,"index_9":false,"index_10":false,"index_11":false,"index_12":true,"index_13":false,"index_14":false,"index_15":false,"index_16":false,"alphabetical":"A"},{"user_id":"4","first_name":"Richard","last_name":"ABOAF","societe_1":"Lyc\u00e9e ORT","societe_2":false,"index_1":false,"index_2":false,"index_4":false,"index_5":false,"index_6":false,"index_7":false,"index_8":true,"index_9":false,"index_10":false,"index_11":false,"index_12":false,"index_13":false,"index_14":false,"index_15":false,"index_16":false,"alphabetical":"A"},":false,"alphabetical":"S"},{"user_id":"679","first_name":"Giulia","last_name":"SILVESTRINI","societe_1":"actas.it","societe_2":false,"index_1":false,"index_2":false,"index_4":false,"index_5":false,"index_6":false,"index_7":false,"index_8":false,"index_9":false,"index_10":false,"index_11":false,"index_12":true,"index_13":false,"index_14":false,"index_15":false,"index_16":false,"alphabetical":"S"}]
}
这是我的循环(每个字母都有不同的循环):
<div class="content">
<ul>
<li ng-repeat="user in users | filter: { alphabetical: 'A'} | filter:query">
<p><strong>{{user.first_name}} {{user.last_name}}</strong> <span ng-hide="user.societe_1 == ''" class="societe">{{user.societe_1}}</span> <span ng-hide="user.societe_2 == ''" class="societe">{{user.societe_2}}</span></span></p>
</li>
</ul>
</div>
所以,这没关系,我使用输入:text来搜索firstname和lastname。 但我的问题是,如何使用复选框来过滤我的循环?
我试过了:
<p class="checkbox"><label for="">Collectivités, service public</label> <input type="checkbox" ng-model="index_2.true"></p>
但它不起作用
答案 0 :(得分:1)
您可以应用与alphabetical
fitler相同的逻辑,例如:
... | filter:{index_2: index_2}
虽然,复选框模型必须存在于范围内,所以:
ng-model="index_2.true"
应该是(虽然不一定是index_2
):
<input type="checkbox" ng-model="index_2">