orderBy是否与AngularUI类型一起使用?

时间:2014-03-01 10:35:15

标签: angularjs angular-ui angular-ui-bootstrap angular-ui-typeahead

这个问题是related to another question我问过。

我设法让AngularUI Typeahead工作。但是,我的orderBy过滤器似乎没有做任何事情。

此选择框可正确排序所有内容(距离是自定义函数):

<select ng-model="fromStation"
ng-options="item.name for item in stations.station | orderBy:distance">

但是这种类型:

<input type="text" ng-model="fromStation" 
typeahead="item as item.name for item in stations.station 
| filter:$viewValue | limitTo:8 | orderBy:distance">

根本不改变顺序(即它按字母顺序排序)。我想要实现的是,当用户键入a的第一个字母 - 在这种情况下 - 火车站时,最接近他的包含该字母的站将首先出现。是否可以使这项工作或此功能尚未提供?

1 个答案:

答案 0 :(得分:3)

如果没有看到最小的重现场景,很难100%确定(这就是为什么使用http://plnkr.co/或类似内容包含实时,最小的示例总是一个好主意)但是查看HTML代码我认为问题在于应用过滤器的顺序

如果您首先应用limitTo过滤器,它将仅从未排序的数组中删除前8个结果,然后将对截止集进行排序。请尝试恢复orderBylimitTo过滤器的顺序,如下所示:

<input type="text" ng-model="fromStation" typeahead="item as item.name for item in stations.station | filter:$viewValue | orderBy:distance | limitTo:8">

看看这是否有效,如果没有 - 使用plunker发布最小重现场景。

相关问题