【发布时间】:2016-09-16 16:42:21
【问题描述】:
我有一个包含多个过滤器字段的表(每列一个)。
<table>
<tr>
<th><input type="text" ng-model="search.name"></th>
<th><input type="text" ng-model="search.phone"></th>
<th><input type="text" ng-model="search.secret"></th>
<th><input type="text" ng-model="search.nullcol"></th>
</tr>
<tr ng-repeat="user in users | filter:search:strict">
<td>{{user.name}}</td>
<td>{{user.phone}}</td>
<td>{{user.secret}}</td>
<td>{{user.nullcol}}</td>
</tr>
</table>
除了过滤包含空值的列外,一切正常:当我在过滤字段中键入内容时,所有带有 null 的行都会消失(正确),但删除过滤器不会恢复它们。
这里有一个 plunkr:https://plnkr.co/edit/viMHsxBHI4CjfjWqWjti
有没有办法让它工作?
【问题讨论】:
-
我可能已经找到了解决方案:我在过滤器字段上放置了一个监视,当为空时,我从搜索对象中删除了该属性。这是更新后的 plunkr:plnkr.co/edit/7wE58QBUAqPHe8CGb4Bj 不过,我想知道是否存在更优雅的解决方案。
标签: javascript angularjs