编程语言
首页 > 编程语言> > javascript-AngularJS:一次选择ui-select不能删除除更改选项以外的所选选项

javascript-AngularJS:一次选择ui-select不能删除除更改选项以外的所选选项

作者:互联网

我正在使用ui-select从服务器&获取数据.在下拉列表中进行填充(搜索和选择).我为您创建了一个plunker.

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

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

解决方法:

您应该使用其他主题(如select2)来完成这项工作.我已升级您的PLUNKER,以显示其工作方式.将allow-clear =“ true”添加到ui-select-match中,并将theme设置为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>

标签:ui-select,angularjs,javascript
来源: https://codeday.me/bug/20191120/2042007.html