1

我在一个二维数组上使用嵌套ng重复,我已经在第三个ng重复使用ng模型,但我的ng模型不是将数据存储在对象中。ng模型不存储数据嵌套ng重复在二维数组

JavaScript代码

emrService 
.getData("checkJson",id) 
    .then(function(data){ 
     if(data.success){ 
     if(data.data != ""){ 
      $scope.jSONCheck1 = JSON.parse(data.data); 
      $scope.tableData = []; 
      for(var k=0;k<$scope.jSONCheck1.length;k++){ 
      var twoD = []; 
      var cols = $scope.jSONCheck1[k].columns; 
      twoD.push(cols); 
      for(var i=0;i<$scope.jSONCheck1[k].rows.length;i++){ 
      var row = []; 
      row.push($scope.jSONCheck1[k].rows[i]); 
      // remaining ans empty values 
      for(var j = 0;j<cols.length-1;j++){ 
       row.push(""); 
      } 
      twoD.push(row); 
      } 
      $scope.tableData.push(twoD); 
      } 
      }else{ 
       $scope.jSONCheck = []; 
      } 
      if($scope.jSONCheck.length != 0) 
      console.log($scope.jSONCheck); 
      } 
      }); 
      } 

HTML代码

<table ng-repeat="table in tableData" class="col-lg-12 sections ng-scope" 
style="width:100%; border: solid; border-width: 0.1px;"> 
<tr ng-repeat="list in table track by $index"> 
<td style="border: solid; border-width: 0.1px; padding: 5.4px;" ng- 
    repeat="c_list in list track by $index"> 
    <input style="width:100%;" type="text" ng-model="list.c_list[$index]" ng- 
    hide="(table.indexOf(list) == 0) || (list.indexOf(c_list) == 0)"/> 
    <strong><span ng-if="(table.indexOf(list) == 0) || (list.indexOf(c_list) 
    == 0)" ng-bind="c_list"></span></strong> 
    </td> 
    </tr> 
</table> 
+0

在你的问题中添加'$ scope.tableData'结果作为'json' – Maher

+0

@Ahmad:有3个'ng-repeat'并且所有都创建'新的子范围',所以'parent ng-repeat'有,只需添加类似号码。 '$ parent',基本上是为了访问firstArray索引,从3ng-repeat,do:'$ parent。$ parent。$ index' – anoop

回答

0

要得到父母的索引ng-重复你必须通过指数等为$父。$指数

HTML代码

<table ng-repeat="table in tableData" class="col-lg-12 sections ng-scope" style="width:100%; border: solid; border-width: 0.1px;"> 
    <tr ng-repeat="list in table track by $index"> 
     <td style="border: solid; border-width: 0.1px; padding: 5.4px;" ng- repeat="c_list in list track by $index"> 
      <input style="width:100%;" type="text" ng-model="list.c_list[$parent.$index]" ng- hide="(table.indexOf(list) == 0) || (list.indexOf(c_list) == 0)" /> 
      <strong><span ng-if="(table.indexOf(list) == 0) || (list.indexOf(c_list) 
    == 0)" ng-bind="c_list"></span></strong> 
     </td> 
    </tr> 
</table> 

希望这会对你有所帮助。

+0

nop @Manoj Patidar。它使事情变得最糟糕 –