加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 当使用选项组时,如何使用Angular UI正确初始化Sele

发布时间:2020-12-17 07:25:57 所属栏目:安全 来源:网络整理
导读:我一直试图让我的角度ui select2指令初始化,并且无法让它与选项组一起使用. 代码: function testCtrl1($scope){ $scope.selectedOptions = ['1']; $scope.categories = [ {label: 'cat1',options: [{desc: 'one',value: 1}]},{label: 'cat2',options: [{des
我一直试图让我的角度ui select2指令初始化,并且无法让它与选项组一起使用.

代码:

function testCtrl1($scope)
{
    $scope.selectedOptions = ['1'];
    $scope.categories = [
            {label: 'cat1',options: [{desc: 'one',value: 1}]},{label: 'cat2',options: [{desc: 'two',value: 2}]}
    ];
}

HTML:

<select multiple ui-select2 ng-model="selectedOptions" style="width: 300px">
    <optgroup ng-repeat="category in categories" label="{{category.label}}">
      <option ng-repeat="option in category.options" value="{{option.value}}">{{option.desc}} - {{option.value}}</option>
    </optgroup>
</select>

小提琴:
我创建了以下jsfiddle.

虽然这样做,但我注意到如果我包含第二个不包含选项组的select2指令(奇怪),它将正确初始化.当我包括第二个select2时,我注意到其他一些奇怪的行为,但我并不太关心它,因为我的目标只是让testCtrl1工作.

下载最新的angular-ui select2并更新第24行:
repeatOption = tElm.find( 'optgroup[ng-repeat],optgroup[data-ng-repeat],option[ng-repeat],option[data-ng-repeat]' );

现在它支持选项组.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读