2017-05-11 9 views
2

各 "セクション"内ですでに選択されているオプションを無効にしようとしていますが(ng-repeatループごとにリセットします)、この状況に最善の方法で対処できません。NgRepeat内のNgOptionsのオプションを無効にする

私は 'disabled when'を使うべきだと知っていますが、各選択オプションがすでに選択されているときに、その配列(array?)またはトラックを作成する方法を理解できません(ngRepeatループ内の他の選択に対して無効にします。セクション内の同じ選択オプションを選択する機能できるようにする必要があります「セクションを。」

何かアドバイスがはるかに高く評価されています。事前に感謝を! 私は一例で最高の学び、うまくいけば、これはAngularJSを学ぶ他の人に有益になります。

このプランナーに見られるように:Plunker

は、私は、次のAngularJsマークアップあなたは(:disable whenキーワードでクイック検索)documentation hereng-optionsのために無効な構文disable when conditionを使用することができます

<body ng-app="app"> 
<div ng-controller="main"> 
    <hr> 
    <div ng-repeat="section in sections track by section.sectionid" ng-model="section.sectionid"> 
    <p>Section</p> 
    <div ng-model="typeModel" ng-repeat="type in types | filter:section.sectionid"> 
     <p>item name</p> 
     <select ng-model="itemSelected" ng-options="item.name for item in items track by item.id"> 

     </select> 

    </div> 
    <hr> 
    </div> 

</div> 

答えて

2

を持っています。

UPD
ng-options="item.name disable when item.name==='2' for item in items track by item.itemid" 

:あなたの状況について

、することができますメンテナンスsectionidのキーでobject(設定およびセクションIDによって入手しやすい)とセクションのそれぞれについては、動的にそれぞれの無効化条件を生成しますselect要素。

// object looks like this 
$scope.sectionSelectedItem = { 
    1: [ 
    concition1,  // for first select of sectionid(1) 
    concition2,  // for second select of sectionid(1) 
    ... 
    ], 
    2: [ 
    concition1,  // for first select of sectionid(2) 
    concition2,  // for second select of sectionid(2) 
    ... 
    ], 
    ... 
} 

、あなたはセクションのselect要素を変更するたびに、あなたはng-changeによって現在のセクションのための条件データを生成することができます。

プランカdemo

+0

ありがとうございますが、これをセクション間でどのように動的に行うのですか? – spookybot

+0

@spookybotセクションに応じて無効条件を変更することができます。 – Pengyy

+0

@spookybotもう一度この例を見て、 'types'配列に特別な条件を追加しました。 – Pengyy

関連する問題