简体   繁体   English

带有ng-model的角度过滤表不起作用

[英]Angular filtering table with ng-model not working

I'm trying to filter a table by one or more columns. 我正在尝试按一个或多个列过滤表。

The problem is that there are rows in the table that do not have all fields, as they can be empty. 问题在于表中的行没有全部字段,因为它们可以为空。

Then, only the rows that have all data fields are displayed before I make any search, the "ng-repeat" doesn't show this rows. 然后,在进行任何搜索之前,仅显示具有所有数据字段的行,“ ng-repeat”不会显示此行。

My code in HTML: 我的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' : ''">

I have also tried to change the ng-model = "searchUS. $" for "searchUS", but I get the input as placeholder [object] [object]. 我也尝试过将ng-model =“ searchUS。$”更改为“ searchUS”,但是我将输入作为占位符[object] [object]。

In this example it works perfectly: link . 在此示例中,它可以完美运行: link

I change the array removing the number field and it works. 我更改数组删除数字字段,它的工作原理。

In my case, the field may be empty is an array, and it is the problem. 在我的情况下,该字段可能为空是一个数组,这就是问题所在。

Any idea? 任何想法?

Thank you very much. 非常感谢你。

I've managed to fix by doing the following: 我设法通过执行以下操作来修复:

<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' : ''">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM