现在是 2075 年,不朽的人类奴役了凡人。有一家商店出售凡人 friend ,并正在尝试构建该应用程序,以便客户可以通过使用他们最喜欢的品牌过滤他们的 friend 来管理他们的 friend 。但显然 angular.js 已损坏。
<select ng-model="searchText2.id" ng-options="friend.brand.id as friend.name for friend in friends">
<option value="">Select</option>
</select>
<tr ng-repeat="friend in friends | filter:{brand:searchText2 || undefined}">
我在这里进行了很好的过滤,请不要误会我的意思,但是如果我单击选择时过滤器没有重置,用户体验管理器会将我提供给网络白化狮。
这是骗子 ---> http://plnkr.co/edit/1MPc0BqQGPNIJZ9FRR6z?p=preview
最佳答案
我已经更新了 plunker并提供一个可能的解决方案。
在过滤器
中,您可以使用三元语句来执行您想要的操作。
<tr ng-repeat="friend in friends | filter:{ brand:(searchText2.id === null) ? {id: undefined}: searchText2}">
当您选择“选择名称”的默认选项时,Angular 会将值设置为 null
,但您希望传入 未定义
来清除过滤器。
希望对您的追求有所帮助!
关于javascript - 在 friend 内部按friend.brand.id进行 Angular 过滤可以工作,但不能使用||当 NULL 时重置过滤器的未定义技巧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32365044/