AngularJS:ui-select 一旦选择,除了更改选项之外无法删除所选选项

3 javascript angularjs ui-select

我正在使用 ui-select 从服务器获取数据并将其填充到下拉列表中(搜索和选择)。我为你创造了一个笨蛋。

<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
    <ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="country in countries | filter: $select.search">
        <span ng-bind-html="country.name | highlight: $select.search"></span>
        <small ng-bind-html="country.code | highlight: $select.search"></small>
    </ui-select-choices>
</ui-select>
Run Code Online (Sandbox Code Playgroud)

一旦我从选择器中选择了任何值,我就可以进一步更改。但无法去除。我怎样才能做到这一点?

lin*_*lin 6

您应该使用其他主题来select2完成这项工作。我升级了你的PLUNKER以展示它是如何工作的。添加allow-clear="true"ui-select-match并将主题设置为theme="select2"以允许取消选择项目。

<ui-select ng-model="country.selected" 
           theme="select2" 
           ng-disabled="disabled">
      <ui-select-match allow-clear="true" placeholder="Select country">
            {{$select.selected.name}}
      </ui-select-match>
      <ui-select-choices repeat="country in countries | filter: $select.search">
            <span ng-bind-html="country.name | highlight: $select.search"></span>
            <small ng-bind-html="country.code | highlight: $select.search"></small>
      </ui-select-choices>
</ui-select>
Run Code Online (Sandbox Code Playgroud)