简体   繁体   English

limitTo具有更复杂表达的angularjs?

[英]limitTo angularjs with more complex expression?

I want to display limited result of my ng-repeat , so first thing that come into my mind was limitTo. 我想显示ng-repeat有限结果,所以我想到的第一件事是limitTo。 However its expression limitTo: 5 seem not solving my problem. 但是其表达式limitTo:5似乎不能解决我的问题。

I wish I can do more complex thing with limitTo, eg. 我希望我可以使用limitTo做更复杂的事情,例如。 display limit of results of certain group, like display only 50 cars which from USA. 显示特定组的结果限制,例如仅显示来自美国的50辆汽车。

Use :filter in your ng-repeat 在ng-repeat中使用:filter

<div ng-init="friends = [{name:'John', phone:'555-1276'},
                         {name:'Mary', phone:'800-BIG-MARY'},
                         {name:'Mike', phone:'555-4321'},
                         {name:'Adam', phone:'555-5678'},
                         {name:'Julie', phone:'555-8765'},
                         {name:'Juliette', phone:'555-5678'}]"></div>

Search: <input ng-model="searchText">
<table id="searchTextResults">
  <tr><th>Name</th><th>Phone</th></tr>
  <tr ng-repeat="friend in friends | filter:searchText">
    <td>{{friend.name}}</td>
    <td>{{friend.phone}}</td>
  </tr>
</table>
<hr>
Any: <input ng-model="search.$"> <br>
Name only <input ng-model="search.name"><br>
Phone only <input ng-model="search.phone"><br>
Equality <input type="checkbox" ng-model="strict"><br>
<table id="searchObjResults">
  <tr><th>Name</th><th>Phone</th></tr>
  <tr ng-repeat="friendObj in friends | filter:search:strict">
    <td>{{friendObj.name}}</td>
    <td>{{friendObj.phone}}</td>
  </tr>
</table>

Reference 参考

You can use multiple filters in the ng-repeat. 您可以在ng-repeat中使用多个过滤器。

Here is the Fiddle . 这是小提琴

<div ng-repeat="people in peoples | filter:{country:'usa'} | limitTo:3">
            {{people.name}}
      </div>

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

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