2017-09-13 90 views
0

我創建了一個Plunker我的代碼顯示問題here生成:AngularJS - - 如何在複選框選擇顯示/隱藏表列從嵌套NG重複

正如你可以看到當你點擊例如'de'複選框會切換顯示/隱藏表格標題 - 但不是列標題下的<textarea>值,對應於區域設置(在本例中爲'de'),這正是我目前試圖使用的。

我不能想到一種方法來鏈接<textarea>取決於locale.Selected複選框的值。所以當locale.Locale == res.LocaleID我想顯示/隱藏取決於locale.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> 

試圖implment像here - 由此用戶可以在複選框,單擊它會觸發隱藏/顯示錶列。

請注意:我的演示plunker是我更大的項目問題,只是例子,所以我必須對不斷變化的JSON格式等沒有控制

回答

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

添加這個方法來你的控制器:

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

這種情況下添加到您的視圖:

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

一個工作演示:http://plnkr.co/edit/neQtu8qxQQVP2kDIY5ru?p=preview