【问题标题】:ui-select with single select (limit attribute is not working)带有单选的 ui-select(限制属性不起作用)
【发布时间】:2016-07-08 06:46:35
【问题描述】:

这是我的代码。我使用了角度 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>

【问题讨论】:

  • 还有其他方法可以将选择限制为一个吗?

标签: jquery angularjs angular-ui angular-ui-select


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      相关资源
      最近更新 更多