AngularJS与limitEd冲突并在ng repeat中过滤

时间:2014-11-28 09:41:58

标签: javascript angularjs angularjs-ng-repeat

我有ng-repeat有很多关键字(> 100 000),这就是我使用limitTo:的原因,但我希望能够搜索到所有关键字。

Search: <input ng-model="filter:queryKeywords" type="text" placeholder="Filter" autofocus>

<label ng-repeat="k in keywords | limitTo:totalDisplayed | orderBy | filter:queryKeywords">
   {{k}}
</label> 

<!-- Will load 100+ keywords -->
<button class="btn btn-primary" ng-click="seeMore()">See More</button>

问题我的搜索仅适用于我能看到的项目。

我想搜索所有项目(即使是我无法显示的项目)。

谢谢!

2 个答案:

答案 0 :(得分:9)

您应该更改过滤器的顺序,以便首先进行搜索(因此适用于所有数据),然后进行限制/排序:

ng-repeat="k in keywords | 
           filter:queryKeywords |
           limitTo:totalDisplayed |
           orderBy"

答案 1 :(得分:4)

Angular按顺序应用过滤器。更改过滤器的顺序可以解决您的问题。

<label ng-repeat="k in keywords | filter:queryKeywords | limitTo:totalDisplayed | orderBy">

这意味着:首先过滤,然后将结果限制为totalDisplayed并最终订购。