【问题标题】:angular-ui/ui-select dropdown start withangular-ui/ui-select 下拉列表以
【发布时间】:2016-01-02 08:48:44
【问题描述】:

是否可以按照开头在下拉列表中显示项目?

我正在使用这个https://github.com/angular-ui/ui-select,从下拉菜单中,如果我写“a”,它会显示所有带有“a”的单词

我只想显示以“a”开头的单词

有指令https://github.com/angular-ui/ui-select/wiki/ui-select-match,但不知道该怎么做

http://embed.plnkr.co/WyIC087njDHLmIVGTAj7/preview

我想在 angular.js 中做同样的事情:Select2 jQuery Plugin: Is there a way to sort a list of tags alphabetically?

【问题讨论】:

    标签: javascript jquery angularjs angular-ui angular-ui-select


    【解决方案1】:

    您可能需要稍微调整一下,但是...

    您可以编写一个自定义过滤器函数,如果第一个字符是“a”,则返回 true:

        <ui-select ng-model="card.id">
        <ui-select-match>{{$select.selected.name}}</ui-select-match>
        <ui-select-choices repeat="item.id as item in users | filter:criteriaMatch($select.search)">
            <div ng-bind-html="item.name | highlight: $select.search"></div>
        </ui-select-choices>
    </ui-select>
    

    然后在 javascript 中执行如下操作:

    $scope.criteriaMatch = function( s ) {
      return function(val) {
        val.charAt(0) == s;
      }
    };
    

    【讨论】:

    • 好的,但这不仅仅是“a”:)
    • 这仍然有效...只需对其进行一点修改并更改您传递给函数的内容...将 $select.search 传递给过滤器函数...查看我的编辑。所以你现在要做的是返回一个更高阶的函数,以便除了 item 的值之外,还可以自己将值传递给 filter 函数
    猜你喜欢
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    相关资源
    最近更新 更多