【问题标题】:using ng-repeat filter without hiding filtered out rows使用 ng-repeat 过滤器而不隐藏过滤掉的行
【发布时间】:2014-01-21 13:45:05
【问题描述】:

我正在尝试执行以下操作: 1.使用ng-repeat创建html表格。 2. 使用输入框供用户输入文字 3. 当文本包含在一组特定的单元格中时,相关的行将执行某种动画(比如说改变它们的背景颜色)。

到目前为止,我一直使用带有过滤器选项的 ng-repeat,但它隐藏了不符合条件的行,而我希望它们显示出来。

这是我当前的代码:

<input id="filterPositions" ng-change="showFiltered()" type="search" ng-model="q.secret" placeholder="filter position..." />
<table> 
<tr ng-repeat="record in (filteredItems = ( body | filter:q:containsComparator ) ) track by record.positionId" ng-class="rowClass(record)">
<td>....</td>
<td>....</td>
<td>....</td>
<td>....</td>
</tr>
</table>

谢谢

【问题讨论】:

    标签: javascript angularjs angularjs-ng-repeat angularjs-filter


    【解决方案1】:

    我认为在这种情况下不需要过滤器。例如,您可以使用简单的 ng-repeat 和 ng-class 指令

    <tr ng-repeat="record in allrecords" ng-class="{'containscmp': isContainsComparator(record)}">
      <td>....</td>
      <td>....</td>
      <td>....</td>
    </tr>
    

    如果记录包含用户输入,则 $scope.isContainsCoparator(record) 函数返回 true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多