Angularjs的ui-select-choices会根据输入的字母顺序下拉
angularjs ui-select-choices dropdown aphabetical order depending on the input given
我正在使用https://github.com/angular-ui/ui-select为我正在工作的网站。目前代码如下:
<ui-select ng-model="model.states">
<ui-select-match placeholder="State">
{{$item.Name}}
</ui-select-match>
<ui-select-choices repeat="item.Code as item in statesArray | filter:$select.search">
{{item.Name}}
</ui-select-choices>
</ui-select>
当我在输入域中输入任何东西时,例如"a", ui-select-choices将显示包含"a"的所有字段。(默认情况下)。我想做的是,我想展示所有以& & & &开头的状态只有。如果在输入框中没有键入任何内容,则按字母顺序显示所有字段。谁能提出一个解决方案?我看到了一些其他的帖子,但还没有人回答这个问题。提前谢谢。
<标题> 例子这里有一个例子,假设states数组中有加利福尼亚,康涅狄格,阿拉斯加,亚利桑那,纽约。
如果在输入字段中没有输入任何内容,则下拉框应显示阿拉斯加、亚利桑那、加利福尼亚、康涅狄格、纽约(可以使用orderBy过滤器实现)。
如果用户输入"a"在输入字段中,下拉框应该显示Alaska, Arizona,而不是其他字段,因为Alaska和Arizona只是以"a"开头的字段。如果用户输入&;c&;,下拉框应该显示加利福尼亚州,康涅狄格州。如果用户输入"ca",下拉菜单应该只显示加州,因为它只匹配给定的输入字符串。
标题>如果我没理解错的话,我认为你所需要做的就是加上
| orderBy:"名字"
<ui-select-choices repeat="item.Code as item in statesArray | filter:$select.search | orderBy:'Name'">
{{item.Name}}
</ui-select-choices>
查看orderBy获取更多信息
经过一番调查,在Tomy和KreepN的帮助下,我找到了答案。在这里,
<ui-select ng-model="model.states">
<ui-select-match placeholder="State">
{{$item.Name}}
</ui-select-match>
<ui-select-choices repeat="item.Code as item in statesArray | startsWith:$select.search | orderBy:'Code'">
{{item.Name}}
</ui-select-choices>
</ui-select>
startsWith Filter如下:
.filter('startsWith', function() {
return function(array,search) {
if(!_.isUndefined(array) && !_.isUndefined(search)) {
var matches = [];
for (var i = 0; i < array.length; i++) {
if (array[i].Name.toUpperCase().indexOf(search.toUpperCase()) === 0 &&
search.length <= array[i].Name.length) {
matches.push(array[i]);
}
}
return matches;
}
};
});
我尝试了上面所有的选项,但我只在这种情况下取得了结果。
<ui-select-choices repeat="group in groups | filter: $select.search | orderBy:['name']">
{{ group.name }}
</ui-select-choices>
相关文章:
- 我正在使用角度 ui-select 进行下拉.如何在控制器中获取所选值
- UI Select在删除后不会更新模型
- 如何使用angular ui select过滤两个字段中的数据
- 角度 ui-select 绑定到一个属性,但向用户显示另一个属性
- AngularJS ui-select,如何初始化多选值
- 如何显示下拉 Angularjs-ui-select onclick on 超链接标签
- 如何显示uI-select(angularjs)时,单击html元素
- AngularJS ui-select - 不选择下拉列表中的选项
- JavaScript - ui-select and objects
- 使用 ui-select 与 Angularjs 和 ajax 值
- Angularjs ui-select tagging 不起作用
- Angularjs validation for ui-select multiple
- 使用默认选定的其他数据源时,从 ui-select 选项中删除重复项
- 将 Angular.js ui-bootstrap 或 ui-select 指令包装在自己的指令中
- 有棱角的如何将ui.select注入到使用xeditable的指令中
- angular ui select中的ng disabled选项会缩小文本框
- 用按钮更改JQuery-ui-select选项
- 以前的值不会显示在Angular UI Select上
- AngularJS将模型传递给ui select
- Angularjs的ui-select-choices会根据输入的字母顺序下拉