【问题标题】:Angular filtering table with ng-model not workingng-model 的角度过滤表不起作用
【发布时间】:2016-10-05 04:21:36
【问题描述】:

我正在尝试按一列或多列过滤表格。

问题在于表中的某些行并不包含所有字段,因为它们可能为空。

然后,在我进行任何搜索之前,只显示具有所有数据字段的行,“ng-repeat”不会显示这些行。

我的 HTML 代码:

<input ng-show="combo.num == 0" type="text" class="form-control" ng-model="searchUS.$"/>
<input ng-show="combo.num == 1" type="text" class="form-control" ng-model="searchUS.subject"/>

<input ng-show="combo.num == 2" type="text" class="form-control" ng-model="searchUS.status"/>
<input ng-show="combo.num == 3" type="text" class="form-control" ng-model="searchUS.tags"/>


<tr ng-repeat="row in rowCollectionUserStories 
               | orderBy:sortType:sortReverse |filter:searchUS"
                ng-class="row.selectedCell ? 'cellSelectedClass' : ''">

我也尝试将 ng-model = "searchUS.$" 更改为 "searchUS",但我将输入作为占位符 [object] [object]。

在此示例中,它完美运行:link。

我更改了删除数字字段的数组,它可以工作。

在我的情况下,该字段可能为空是一个数组,这就是问题所在。

有什么想法吗?

非常感谢。

【问题讨论】:

  • 错误的示例链接?
  • 是的,链接错误。已经更正了。

标签: javascript angularjs angularjs-filter


【解决方案1】:

我已经设法通过执行以下操作来修复:

<input ng-show="combo.num == 0" type="text" class="form-control" ng-model="searchUS.$"/>
<input ng-show="combo.num == 1" type="text" class="form-control" ng-model="searchUS.subject"/>

<input ng-show="combo.num == 2" type="text" class="form-control" ng-model="searchUS.status"/>
<input ng-show="combo.num == 3" type="text" class="form-control" ng-model="searchTags"/>


<tr ng-repeat="row in rowCollectionUserStories | orderBy:sortType:sortReverse | 
               filter: (combo.num == 3 ? {tags: searchTags} : searchUS)"
                    ng-hide="row.sprint !== undefined"
                    ng-class="row.selectedCell ? 'cellSelectedClass' : ''">

【讨论】:

    猜你喜欢
    • 2015-09-28
    • 1970-01-01
    • 2015-11-21
    • 2017-11-29
    • 2023-04-03
    • 1970-01-01
    • 2016-11-24
    • 2014-08-20
    • 1970-01-01
    相关资源
    最近更新 更多