I have a 2D nested object like this
$scope.analysisDataNew = [
{
"data":{
"row1":{
"col1":{
"subCol1": 10,
"subCol2": 10,
},
"col2":{
"subCol1": 10,
"subCol2": 10,
"subCol3": 10,
},
"col3":{
"subCol1": 10,
},
},
"row2":{
"col1":{
"subCol1": 10,
"subCol2": 10,
},
"col2":{
"subCol1": 10,
"subCol2": 10,
"subCol3": 10,
},
"col3":{
"subCol1": 10,
},
},
}
}
];
I am trying to use it for creating a table for with ng-repeat.
What i have tried so far is this
for (var i = 0; i < $scope.analysisDataNew.length; i++) {
// row list
$scope.analysisDataNew[i].xAxis = Object.keys($scope.analysisDataNew[i].data);
// col list
if($scope.analysisDataNew[i].subCol){
var rows = Object.keys($scope.analysisDataNew[i].data);
var cols = $scope.analysisDataNew[i].data[rows[0]];
var colList = [];
for(var j=0; j<Object.keys(cols).length; j++){
colList.push({name: Object.keys(cols)[j]});
colList[j].subcol = [];
for(var k=0; k < Object.keys(cols[Object.keys(cols)[j]]).length; k++){
colList[j].subcol.push(Object.keys(cols[Object.keys(cols)[j]])[k]);
};
};
$scope.analysisDataNew[i].colList = colList;
} else {
$scope.analysisDataNew[i].colList = Object.keys($scope.analysisDataNew[i].data[$scope.analysisDataNew[i].xAxis[0]]);
};
console.log($scope.analysisDataNew[i]);
};
When there is no sub-column i am easily able to print the data but the problem is with sub-column.
Can anybody please help??