我有一个使用过滤器的角度应用。我的json文件如下所示:
[{DegreeCategoryID:"1",DegreeCategory:"Accounting",DegreeCategoryType:"Applied Sciences"},
{DegreeCategoryID:"2",DegreeCategory:"Advanced Manufacturing/Mechatronics Technology",DegreeCategoryType:"Applied Sciences"},
{DegreeCategoryID:"3",DegreeCategory:"Air Conditioning and Refrigeration Technology",DegreeCategoryType:"Applied Sciences"},
{DegreeCategoryID:"4",DegreeCategory:"Auto Body Technology",DegreeCategoryType:"Applied Sciences"},
{DegreeCategoryID:"77",DegreeCategory:"Associate in Arts",DegreeCategoryType:"Academic"},
{DegreeCategoryID:"78",DegreeCategory:"Associate in Sciences",DegreeCategoryType:"Academic"},
{DegreeCategoryID:"79",DegreeCategory:"Associate of Arts in Teaching",DegreeCategoryType:"Academic"},
{DegreeCategoryID:"80",DegreeCategory:"Emphasis",DegreeCategoryType:"Academic"},
{DegreeCategoryID:"81",DegreeCategory:"Field of Study",DegreeCategoryType:"Academic"}]
我使用的语句使用这样的过滤器:
<a href='#' ng-repeat="degree in degrees | filter:search:Academic" class="list-group-item">
<li ng-click="showCourseDescription(p.subchildren)" >{{degree.DegreeCategory}}</li>
</a>
但过滤不会发生。有什么建议吗?
答案 0 :(得分:1)
ngRepeat
表达式应如下所示:
ng-repeat="degree in degrees | filter:{DegreeCategoryType:'Academic'}"
<强>更新强>
如果您想使用搜索字段来指定搜索值:
<input type="search" ng-model="search" />
...
<li ng-repeat="degree in degrees | filter:{DegreeCategoryType:search}">
最后,请记住,您可以指定第三个参数,指示您是否要匹配子字符串或完全匹配:
<input type="search" ng-model="search" />
<input type="checkbox" ng-model="exactMatch" />
...
<li ng-repeat="degree in degrees | filter:{DegreeCategoryType:search}:exactMatch">
另请参阅此 short demo 。