0

这是我的代码。我使用了角度 UI 选择。它工作得很好。但是现在,要求更改为仅选择一次下拉列表。我使用了限制属性,但它不起作用。

<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>
4

2 回答 2

0

限制是在 0.13 版本之后引入的。我用的是 0.12

于 2016-03-24T10:13:44.333 回答
0

使用以下代码清除选定的选项值

HTML 代码

<ui-select-match placeholder=”Enter table…”&gt;
 <span>{{$select.selected.description || $select.search}}</span>
 <a class=”btn btn-xs btn-link pull-right” ng-click=”clear($event, $select)”&gt;<i class=”glyphicon glyphicon-remove”&gt;</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();
}
于 2017-10-23T10:13:26.673 回答