ui-select with single select (限制属性不起作用)
ui-select with single select (limit attribute is not working)
这是我的代码。我用了angularUI-select。它工作得很好。但现在,下拉列表的要求已更改为仅 selected 一次。我使用了 limit 属性,但它不起作用。
<span id="oCountriesSpan" ng-class="{'has-error': noCountriesSelected()}">
<ui-select multiple limit="1" ng-model="countryModel.selectedCountries" ng-disabled="isReadOnly" theme="bootstrap">
<ui-select-match placeholder="Select ..." allow-clear="true">{{$item.name}}
</ui-select-match>
<ui-select-choices repeat="country.id as country in countryCodes | filter:$select.search">
{{ country.name }}
</ui-select-choices>
</ui-select>
</span>
限制是0.13版本后引入的。我用的是 0.12
使用以下代码清除所选选项值
HTML代码
<ui-select-match placeholder=”Enter table…”>
<span>{{$select.selected.description || $select.search}}</span>
<a class=”btn btn-xs btn-link pull-right” ng-click=”clear($event, $select)”><i class=”glyphicon glyphicon-remove”></i></a>
</ui-select-match>
控制器操作代码
function clear($event, $select){
//stops click event bubbling
$event.stopPropagation();
//to allow empty field, in order to force a selection remove the following line
$select.selected = undefined;
//reset search query
$select.search = undefined;
//focus and open dropdown
$select.activate();
}
这是我的代码。我用了angularUI-select。它工作得很好。但现在,下拉列表的要求已更改为仅 selected 一次。我使用了 limit 属性,但它不起作用。
<span id="oCountriesSpan" ng-class="{'has-error': noCountriesSelected()}">
<ui-select multiple limit="1" ng-model="countryModel.selectedCountries" ng-disabled="isReadOnly" theme="bootstrap">
<ui-select-match placeholder="Select ..." allow-clear="true">{{$item.name}}
</ui-select-match>
<ui-select-choices repeat="country.id as country in countryCodes | filter:$select.search">
{{ country.name }}
</ui-select-choices>
</ui-select>
</span>
限制是0.13版本后引入的。我用的是 0.12
使用以下代码清除所选选项值
HTML代码
<ui-select-match placeholder=”Enter table…”>
<span>{{$select.selected.description || $select.search}}</span>
<a class=”btn btn-xs btn-link pull-right” ng-click=”clear($event, $select)”><i class=”glyphicon glyphicon-remove”></i></a>
</ui-select-match>
控制器操作代码
function clear($event, $select){
//stops click event bubbling
$event.stopPropagation();
//to allow empty field, in order to force a selection remove the following line
$select.selected = undefined;
//reset search query
$select.search = undefined;
//focus and open dropdown
$select.activate();
}