2015-10-05 29 views
0
開頭

是否可以按照開頭顯示drodown中的項目?angular-ui/ui-select下拉菜單以

我用這https://github.com/angular-ui/ui-select,並從下拉,如果我寫「一」這表明裏面有所有單詞「一」

我想只顯示其與「一」

開頭的單詞有指令,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?

回答

0

你可能需要調整這一點,但...

如果第一個字符是「」你可以寫一個返回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; 
    } 
}; 
+0

好,但它是不是隻有「一個」 :) – xvi30

+0

仍然工作...只是國防部它一點點,改變你傳遞給函數是什麼?將$ select.search傳遞給過濾器函數...請參閱我的編輯。所以你現在正在做的是返回一個更高階的函數,以便除了項目的值之外還自己給過濾器函數傳遞一個值 – btm1