NG-model 不会在 2D 数组上的嵌套 NG-repeat 上存储数据



我在二维数组上使用嵌套的ng-repeat,我在第三个ng-repeat上使用ng-model,但我的ng-model没有将数据存储在对象中。

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);
            }
            });
            }

网页代码

<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>

要获取父 ng-repeat 的索引,您必须像 $parent.$index 一样传递索引

网页代码

<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>

希望这对您有所帮助。

最新更新