【发布时间】:2017-11-29 05:27:02
【问题描述】:
我已经完成了一些基本的 Angular 过滤,但我遇到了一个小问题,我不知道如何解决它。我有一个带有输入标题的表格。我希望每个输入都按该列过滤表格。问题是尝试将 ng-model 动态设置为相应的列名。我可以硬编码它,但我需要它动态。有没有人做过类似的事情?
编辑:有什么方法可以将密钥从 ng-repeat 签名到 search[key] 之类的,因为我知道插值在 ng-model 中不起作用
代码如下:
<table class="table table-striped">
<thead>
<tr ng-repeat="item in vm.students | limitTo:1">
<th ng-repeat="(key, val) in item">
{{key | format}}
</th>
</tr>
<tr ng-repeat="item in vm.students | limitTo:1">
<th ng-repeat="(key, val) in item">
<input type="text" ng-model='search.key'>
</th>
<tr>
</thead>
<tbody>
<tr ng-repeat="item in vm.students | filter:search.key ">
<td> {{item.id}}</td>
<td> {{item.car}}</td>
<td> {{item.payment_method}}</td>
<td> {{item.currency}}</td>
<td> {{item.city}}</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
【问题讨论】: