首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angularjs选择StartsWith搜索

Angularjs选择StartsWith搜索
EN

Stack Overflow用户
提问于 2016-05-01 19:26:40
回答 1查看 2.4K关注 0票数 1

在我的angularjs应用程序中,我使用的UI select.This是我的Html

代码语言:javascript
复制
<ui-select name="service" multiple ng-model="service.ServiceName" close-on-select="false" >
                <ui-select-match placeholder="Select Services...">{{$item.ServiceName}}</ui-select-match>
                <ui-select-choices repeat="service in Services | filter: {ServiceName: $select.search} | filter:myFilter track by service.ServiceId">
                      {{service.ServiceName}}
                </ui-select-choices>

Select filter提供了包含搜索的内容,但是我想根据StartsWith.I筛选元素,我已经看到了一些StartsWith.I的例子,但是我无法将它们合并到UI Select中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-01 21:12:11

单项: Plunker.

JS

代码语言:javascript
复制
vm.startsWith = function (actual, expected) {
    var lowerStr = (actual + "").toLowerCase();
    return lowerStr.indexOf(expected.toLowerCase()) === 0;
  }

代码语言:javascript
复制
<ui-select-choices repeat="country in ctrl.countries|filter:$select.search:ctrl.startsWith">
      <span ng-bind-html="country.name | highlight: $select.search"></span>
      <small ng-bind-html="country.code | highlight: $select.search"></small>
    </ui-select-choices>

多项: Plunker

JS与上面的内容相同。

代码语言:javascript
复制
<ui-select multiple ng-model="ctrl.multipleDemo.colors" theme="bootstrap" ng-disabled="ctrl.disabled" close-on-select="false" style="width: 300px;" title="Choose a color">
    <ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match>
    <ui-select-choices repeat="color in ctrl.availableColors | filter:$select.search : ctrl.startsWith">
      {{color}}
    </ui-select-choices>
  </ui-select>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36970946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档