我有一个多重过滤器的工作示例(查看 CodePen ),可以按 Material 和结构参数对大量数据进行排序。
<select multiple="multiple" ng-model="selectedMaterial" ng-options="emp.material as emp.material for emp in empList | unique:'material'">
</select>
<table class="table table-bordered">
<tr>
<th>Material</th>
<th>Construction</th>
</tr>
<tr ng-repeat="emp in empList | filterMultiple:{material:selectedMaterial,construction:selectedConstruction}">
<td>{{emp.material}}</td>
<td>{{emp.construction}}</td>
</tr>
</table>
但这是一个问题:我需要做什么才能通过按下按钮来过滤数据?因为我的解决方案不起作用...
<button ng-click="filterMultiple= {material: 'Steel'}">Steel</button>
谢谢!
最佳答案
要添加到上述答案中,对于多重选择,值将在数组中传递。单击“ALL”按钮时,将传递字符串值数组。
在代码中包含 ng-click 按钮。
<div class="panel-body text-center">
<div class="col-xs-3">
<button ng-click="selectedMaterial = 'Steel'">Steel</button>
</div>
<div class="col-xs-3">
<button ng-click="selectedMaterial = ['Polycarbonate']">Polycarbonate</button>
</div>
<div class="col-xs-3">
<button ng-click="selectedMaterial = ['Polypropylene']">Polypropylene</button>
</div>
<div class="col-xs-3">
<button ng-click="selectedMaterial = ['Steel', 'Polycarbonate', 'Polypropylene']">All</button>
</div>
</div>
关于javascript - 如何在 Angular 中仅按一个值过滤数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39475944/