加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:13:12 所属栏目:安全 来源:网络整理
导读:这问题是 related to another question我问的. 我设法让AngularUI Typeahead工作.但是,我的orderBy过滤器似乎没有做任何事情. 此选择框可正确排序所有内容(距离是自定义函数): select ng-model="fromStation"ng-options="item.name for item in stations.st
这问题是 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的第一个字母 – 在这种情况下 – 火车站时,最接近他的包含该字母的站将首先出现.是否可以使这项工作或此功能尚未提供?

解决方法

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

如果您首先应用limitTo过滤器,它将从未排序的数组中切断前8个结果,然后才会对截止集进行排序.尝试恢复orderBy和limitTo过滤器的顺序,如下所示:

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

看看这是否有效,如果没有 – 使用plunker发布一个最小的重现场景.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读