【发布时间】:2018-05-13 08:55:21
【问题描述】:
JSFiddle:http://jsfiddle.net/ADukg/16368/.
如果对象的 JSON 属性与所选选项匹配,我正在尝试通过多个过滤器过滤 ng-repeat 列表中的项目。
So when the 'Unread' filter is selected, items will only be displayed where the 'unread' property of each json object is equal to true, and similarly with the high importance filter.
我还希望能够组合这两个过滤器,以便在同时选择过滤器时列表只显示未读和高重要性属性都等于 true 的项目。
我在上面的 JSFiddle 中有一个基本设置,我在其中使用模型作为过滤器复选框,但一直在寻找一种方法来为列表实现这些过滤器,并且对我如何会为这种情况做我需要的。
HTML:
<div>
<label for="filterByAllCheckbox">Filter by All </label>
<input ng-model="filters.all" ng-change="filterByAll()" type="checkbox" id="filterByAllCheckbox" ng-disabled="filters.all">
</div>
<div>
<label for="filterByUnreadCheckbox">Filter by Unread </label>
<input ng-model="filters.unread" ng-change="manageFilters()" type="checkbox" id="filterByUnreadCheckbox">
</div>
<div>
<label for="filterByHighImportanceCheckbox">Filter by High Importance </label>
<input ng-model="filters.highImportance" ng-change="manageFilters()" type="checkbox" id="filterByHighImportanceCheckbox">
</div>
<br>
<ul>
<b>NOTIFICATIONS</b>
<li ng-repeat="notification in notifications">
{{notification.title}}
</li>
</ul>
【问题讨论】:
标签: javascript angularjs json filter