Presented here is a list of descriptions associated with specific names. I am seeking guidance on how to group or list the descriptions by name.
html:
<body ng-app="app" ng-controller="MainCtrl">
<div ng-repeat="nameGroup in loopData"> <!-- Scope for this ng-repeat should be customizable -->
<div ng-repeat="loopData in nameGroup.values track by $index" ><!-- Scope for this ng-repeat should be customizable -->
<div class="text-center merged">{{loopData.name}}</div><!-- ng-if="$index === 0" -->
<div class="text-center">{{loopData.description}}</div>
</div>
</div>
</body>
controller:
var app = angular.module('app', ['angular.filter']);
app.controller('MainCtrl', function($scope) {
$scope.finalLoopData = {};
$scope.loopData = [{ "country":"Abc", "id":"001", "mynumbers":[],
"values": [
{"description": "first desc", "name": "First Test Name"},
{"description": "second desc", "name": "First Test Name"},
{"description": "third desc", "name": "First Test Name"},
{"description": "fourth desc", "name": "Second Test Name"},
{"description": "fifth desc", "name": "Second Test Name"},
{"description": "sixth desc", "name": "Third Test Name"},
{"description": "seventh desc", "name": "Third Test Name"},
{"description": "eighth desc", "name": "Third Test Name"},
{"description": "ninth desc", "name": "Third Test Name"},
{"description": "tenth desc", "name": "Third Test Name"},
{"description": "eleventh desc", "name": "Fourth Test Name"},
{"description": "twelfth desc", "name": "Fourth Test Name"}
]
}];
$scope.arrayToObject = function () {
var finalLoopData = {};
angular.forEach($scope.loopData[0].values, function (value, key) {
if (!finalLoopData[value.name]) {
finalLoopData[value.name] = new Array();
}
finalLoopData[value.name].push(value);
});
$scope.finalLoopData = finalLoopData;
}
$scope.arrayToObject();
});
Upon executing the code, individual descriptions with names are generated. However, my desired output should resemble the following:
First Test Name
first desc
second desc
- third desc
Second Test Name
fourth desc
fifth desc
Third Test Name
sixth desc
seventh desc
eighth desc
ninth desc
- tenth desc
Fourth Test Name
eleventh desc
twelfth desc
Developed Filter: