I am trying to achieve something like the image below. This is my data
JavaScript
x
9
1
$scope.Reports =
2
[
3
{ Id: 1, Name: 'Report One', Year: 2016, Month: 5 },
4
{ Id: 2, Name: 'Report Core', Year: 2016, Month: 5 },
5
{ Id: 3, Name: 'Report Alpha', Year: 2016, Month: 3 },
6
{ Id: 4, Name: 'Report Moon', Year: 2015, Month: 5 },
7
{ Id: 5, Name: 'Report Sky', Year: 2015, Month: 2 }
8
];
9
The objective is that If you click on any of the numbers underlines the reports that belong to that month hide or show (collapsible). I have tried many things but it seems I cannot figure it out what I need. I have made a JS BIN where my code is.
JavaScript
1
2
1
http://jsbin.com/huhabehoju/edit?html,js,output
2
Any help will be kindly appreciate it. Thanks
JavaScript
1
14
14
1
<body>
2
<div ng-controller="MainController">
3
<ul ng-repeat="(key, value) in Reports | groupBy: 'Year'">
4
{{ key }}
5
<ul ng-repeat="(key1, value1) in value | groupBy: 'Month'">
6
O{{key1}}
7
<li ng-repeat="p in value1">
8
{{p.Name }}
9
</li>
10
</ul>
11
</ul>
12
</div>
13
</body>
14
Advertisement
Answer
this works
JavaScript
1
7
1
$scope.showReport = {};
2
$scope.toggleShow = function (ym) {
3
4
$scope.showReport[ym] = !$scope.showReport[ym];
5
};
6
});
7
in the controller and the html this
JavaScript
1
10
10
1
<ul ng-repeat="(key, value) in Reports | groupBy: 'Year'">
2
{{ key }}
3
<ul ng-repeat="(key1, value1) in value | groupBy: 'Month'">
4
<a ng-click="toggleShow(key+key1)"> O{{key1}} </a>
5
<li ng-repeat="p in value1" ng-if="!showReport[key+key1]">
6
{{p.Name }}
7
</li>
8
</ul>
9
</ul>
10