【问题标题】:disable one or more item in repeat list in ui select在 ui 选择中禁用重复列表中的一项或多项
【发布时间】:2017-07-10 23:43:49
【问题描述】:

我需要在 ui-select repeat 中禁用一个或多个选项

这是一个我想重复的数组

$scope.list = ['item1', 'item2', 'item3', 'item4']

这是一个选择函数

<ui-select ng-model="item"
           on-select="changeItem()"
           ng-disabled="isReadOnly()" required>

    <ui-select-match class="ui-select-match">
        <span ng-bind="$select.selected"></span>
    </ui-select-match>
    <ui-select-choices class="ui-select-choices"
                       repeat="item in list">
        <div class="row">
            <div class="col-md-12">
                <span ng-bind="item"></span>
            </div>
        </div>
    </ui-select-choices>
</ui-select>

例如我想禁用item2item4

我该如何实现它?

【问题讨论】:

    标签: angularjs ui-select


    【解决方案1】:

    如果你想禁用某些选项,你可以使用ui-disable-choice 属性和ui-select-choices 来传递一个表达式来检查。

    在您的情况下,ui-disable-choice="item == 'item2' || item == 'item4'" 之类的东西应该可以工作。

    【讨论】:

    • 此选项不起作用((出现此错误:TypeError: Cannot create property '_uiSelectChoiceDisabled' on string 'item1'
    • @AndriiBlinov 这是ui-select 旧版本的问题,看起来它已在最新版本中修复。问题是表达式的结果被存储为像item._uiSelectChoiceDisabled = isDisabled; 这样的项目的属性,这就是您收到上述错误的原因。您可以尝试更新ui-select,或者您可以使用$scope.list = [{value : 'item1'}, {value : 'item2'}, {value : 'item3'}, {value : 'item4'}] 之类的项目列表,然后在repeat="item.val as item in list" ui-disable-choice="item.val == 'item2' || item.val == 'item4'" 之类的视图中使用它。
    • 哦。对不起。我忘了回答,是的,它有效,我使用了一个对象。谢谢)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多