【问题标题】:angularJS filter using array type(?) ng-modelangularJS过滤器使用数组类型(?)ng-model
【发布时间】:2018-04-11 06:49:57
【问题描述】:

我想让过滤器只在一个元素上工作。 为了制作过滤器,我搜索了 SO,并找到了制作我想要的方法。 But I used 'select' tag to choose element applies to filter, I got problem when selected value is NULL.

<div class="input-group">
    <select class="form-control" ng-model="setParam">
        <option value="">All</option>
        <option value="atName">Name</option>
        <option value="atComp">Company</option>
        <option value="atDep">Department</option>
        <option value="atPos">Position</option>
        <option value="atTel">Tel</option>
        <option value="atEmail">Email</option>
    </select>
</div>
<div class="input-group">
    <span>
        <input type="text" class="form-control" ng-model="atParam[setParam]">                               
    </span>

<tr data-ng-repeat="row in attendees | filter : atParam">

The problem is getting nothing to display when selected value is NULL. 除 NULL 之外的所有内容都运行良好。如果解决了该怎么办? 或者,还有其他搜索方式吗?谢谢!

【问题讨论】:

  • null 应该是什么意思?
  • atParam 包含什么
  • atParam 是输入文本框。 Null 表示第一个搜索选项

标签: html angularjs angularjs-filter


【解决方案1】:

我认为您的要求是当您选择ALL 时应显示所有记录。但你什么也得不到。

为此,您需要将condition 添加到filter,具体取决于setParam

<tr data-ng-repeat="row in attendees | filter : setParam ? atParam : ''">

这是做什么的,

  • 它将首先搜索 setParam。
  • 如果是not null,则使用您的atParam 条件。
  • 如果它为空,则过滤empty string,从而显示all records

【讨论】:

  • 谢谢!它完美地工作。我不知道当 setPram 为 null 时如何处理它。
猜你喜欢
  • 2018-02-27
  • 2016-03-07
  • 2015-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多