2017-09-13 13 views
0

私は問題here示す私のコードでPlunkerを作成している:あなたは、例えば上でクリックしたときにあなたが見ることができるようにAngularJS - チェックボックスの選択に/非表示のテーブルの列を表示する方法 - 生成された、ネストされたNG-繰り返しから

を'de'チェックボックスをオンにすると、テーブル見出しの表示/非表示を切り替えることができますが、ロケール(この場合は「de」)に対応するカラム見出しの下の値は<textarea>ではありません。

チェックボックスの値locale.Selectedに応じて、<textarea>をリンクする方法は考えられません。だからlocale.Locale == res.LocaleIDlocale.Selectedの値に応じて表示/非表示にしたいとき。

<table class="table"> 
    <tr> 
     <th>Resource Id</th> 
     <th ng-repeat="locale in view.resourceGridResources.Locales" ng-show="locale.Selected"> 
      {{locale.Locale ? locale.Locale : "invariant" }} 
     </th> 
    </tr> 
    <tr ng-repeat="resource in view.resourceGridResources.Resources"> 
     <td>{{resource.ResourceId}}</td> 
     <td ng-repeat="res in resource.Resources"> 
      <textarea ng-model="res.Value" 
         ng-blur="view.saveGridResource(res)" 
         style="min-width: 300px" 
         //trying to get to locale.Selected here - how get index 'x'? 
         ng-show="view.resourceGridResources.Locales[x].Selected"> 
         </textarea> 
     </td> 

    </tr> 
</table> 

hereのようなものをimplmentしようとすると - ユーザーは、チェックボックスをクリックすることができ、それが表示/非表示のテーブルの列を切り替えることができますせます。

ご注意:

vm.check = function(res) { 
    return vm.resourceGridResources.Locales.find(function(loc) { 
    return loc.Locale === res.LocaleId && loc.Selected; 
    }); 
}; 

:私は

答えて

1

JSに関数を書く必要はありません。 resource.Resourcesの項目数はview.resourceGridResources.Localesの項目数と同じです。

HTML

<td ng-repeat="res in resource.Resources" ng-show="vm.resourceGridResources.Locales[$index].Selected">   
     <textarea ng-model="res.Value" 
        style="min-width: 300px"></textarea> 
    </td> 

ワーキングPlunkerhttp://plnkr.co/edit/Al4KdHlCV2uo9HQ2qNt7?p=preview

+0

ありません。しかしresource.Resourcesの$インデックスはview.resourceGridResources.Localesの$インデックスと並行してのだろうか? – Vivz

1

があなたのコントローラに、このメソッドを追加など、JSON形式の変更を制御することはできませんので、私のデモplunkerは私の非常に大きなプロジェクトでは問題のほんの一例です

<td ng-repeat="res in resource.Resources" ng-show="vm.check(res)"> 

実用デモ:http://plnkr.co/edit/neQtu8qxQQVP2kDIY5ru?p=preview。この条件を表示します。

関連する問題