我在二维数组上使用嵌套的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);
}
});
}
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 :(得分:0)
要获取父ng-repeat的索引,您必须传递索引,如$ parent。$ index
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>
希望这会对你有所帮助。