【问题标题】:multiple checkbox filter in ng-repeatng-repeat 中的多个复选框过滤器
【发布时间】:2018-04-30 23:15:50
【问题描述】:

所以我有一个包含多个checkbox 的搜索栏,当我选中任何一个复选框时,它们将过滤ng-repeat,但是当我选择另一个复选框时它不会返回任何内容?

示例

已取消的复选框和待批准已被选中!

我错过了什么吗?

displayedCollection 值

displayedCollection:[{ "employeeName" : "test user","status" : "Pending Approval"}]

ng-重复

<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" ng-model="cancelled" ng-true-value="'Cancelled'" ng-false-value="">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Cancelled</span>

<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" ng-model="pa" ng-true-value="'Pending Approval'" ng-false-value="">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Pending Approval</span>

html

<tr ng-repeat="leave in displayedCollection | dateRanges:from:to | filter:cancelled | filter:pa">
<td class="text-capitalize">{{ leave.fullName }}</td>
<td>{{ leave.fromDate | date: 'MM/dd/yyyy'}} - {{ leave.toDate | date: 'MM/dd/yyyy' }}</td>
<td>{{ leave.leaveType }}</td>
<td>{{ }}</td>
<td class="text-center">{{ leave.leaveDays }}</td>
<td class="text-center">{{ leave.leaveStatus }}</td>
<td class="text-center">
    <i class="fa fa-comment-o" aria-hidden="true" data-target="#modalComment" data-toggle="modal" ng-click="vm.getComment(leave)"></i>
</td>
<td class="text-center">
    <button type="button" class="btn btn-trans-blue btn-raised btn-xs btn-circle">
        <strong>
            <i class="fa fa-ellipsis-h fa-1x" aria-hidden="true"></i>
        </strong>
    </button>
    <button type="button" class="btn btn-trans-red btn-raised btn-xs btn-circle" ng-click="vm.deleteLeave(leave)">
        <i class="fa fa-trash-o fa-1x" aria-hidden="true"></i>
    </button>
</td></tr>

【问题讨论】:

    标签: javascript angularjs checkbox angularjs-filter


    【解决方案1】:

    在过滤器上使用|| (OR) 运算符。

    <tr ng-repeat="leave in displayedCollection | dateRanges:from:to | filter: (cancelled || pa)">
    

    也根据status属性过滤数据集

    <li ng-repeat="account in accounts | filter:{status : pa ||cancelled  }">{{account}}</li>
    

    Demo

    【讨论】:

    • 试过你的答案,但没有解决问题。
    • 尝试了你更新的答案,它给了我一个日期范围过滤器错误
    • 我已更新您的答案的fiddle 不适用。
    猜你喜欢
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    相关资源
    最近更新 更多