我在用户界面中遇到了类似的问题。我使用angular-ui并将其用于所有我的下拉列表(有几个)。虽然这不是一个天然的选择2选择,角度的用户界面的下拉列表中,可以使用使用属性theme="select2"
要在至少3个字符的输入限制,使下拉菜单,就像选择2,这里就是你要做的:
控制器JS:
$scope.limitTitleSearch = 5000; //this should be initialised to more than the number of entries the dropdown holds
$scope.checkTitle = function(lettersTyped){
if(lettersTyped.length > 2){
$scope.limitTitleSearch = 500;
}else{
$scope.limitTitleSearch = 0;
}
}
HTML:
使用用于输入多于3个字符显示消息。像:
<ui-select-no-choice>
Type at least 3 chars for options to load
</ui-select-no-choice>
和使用的ui-select-choices
的refresh
属性来调用JS功能。
所以你的HTML看起来
<ui-select-choices
refresh="checkTitle($select.search)"
refresh-delay="1000"
repeat="item in (itemArray | filter: $select.search limitTo: limitTitleSearch) track by item.id">
<span ng-bind="item.name"></span>
</ui-select-choices>
//add <ui-select-no-choices code here
希望这有助于。 :)
有限制最少的用户输入长度本地参数,这就是所谓的最小输入长度,它吃的字符数。我缺乏通过ui-select-no-choice提供的选项。虽然它不是我想达到的,但它与最小输入长度结合起来可能适用于大多数情况。 – SuperTukan