【问题标题】:How to filter with default option "All"如何使用默认选项“全部”进行过滤
【发布时间】:2015-09-22 08:17:38
【问题描述】:

我在过滤器下拉列表中添加了默认选项“全部”以显示所有结果,但是当我使用某个组名称过滤然后尝试使用“全部”过滤时,没有显示任何结果。如何在选择所有选项时显示所有结果?

<input type="text" ng-model="search" class="input-control width-100" />

<select ng-model="group" ng-options="gp.groupID as gp.groupName for gp in groups" class="input-control width-100"><option value="" selected>All</option></select>

    <table id="tbl-holidaylist" class="table table-striped table-bordered">
        <thead>
            <th width="40%">Type</th>
            <th width="40%">Group</th>
        </thead>
        <tbody>
            <tr ng-repeat="tp in types |filter:{'groupID':group}|filter:search">
                <td>{{ tp.ExpenseTypeName }}</td>
                <td>{{ tp.ExpenseGroupName }}</td
            </tr> 
        </tbody>
    </table>

【问题讨论】:

  • 我认为您应该清除过滤器而不是尝试过滤“全部”。
  • 显示您合并All的代码。
  • 不知何故没有正确更新..现在你可以看到完整的代码..

标签: javascript angularjs


【解决方案1】:

我创建了你的应用,这里是Link

<tr ng-repeat="tp in types |filter:(group && {'groupID':group})|filter:search">

问题是当全部被选中时,组变得未定义,导致过滤器不起作用

【讨论】:

  • @user2866086 这是你想要的吗
  • 是的..但不知道为什么我的代码中同样的事情不起作用:(
  • 你可以在 jsFiddle 或 plunker 中尝试一下并分享链接
【解决方案2】:

我认为您指的是这样的功能

Demo

<select ng-model="selected" ng-options="a as a for a in arr">
    <option value="">All</option>
</select>
<ul>
    <li ng-repeat="a in arr | filter:selected">{{a}}</li>
</ul>

【讨论】:

  • 不知何故没有正确更新..现在你可以看到完整的代码了。
猜你喜欢
  • 2018-07-03
  • 1970-01-01
  • 2015-06-24
  • 2013-08-29
  • 2020-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
相关资源
最近更新 更多