【发布时间】:2016-08-07 18:03:55
【问题描述】:
我正在尝试实现如下图所示的目标。这是我的数据:
JS:
angular.module('app', ['angular.filter'])
.controller('MainController', function($scope) {
$scope.showReport = {};
$scope.toggleShow = function (ym) {
$scope.showReport[ym] = !$scope.showReport[ym];
};
$scope.Reports = [
{ Id: 1, Name: 'Report One', Year: 2016, Month: 5 },
{ Id: 2, Name: 'Report Core', Year: 2016, Month: 5 },
{ Id: 3, Name: 'Report Alpha', Year: 2016, Month: 3 },
{ Id: 4, Name: 'Report Moon', Year: 2015, Month: 5 },
{ Id: 5, Name: 'Report Sky', Year: 2015, Month: 2 }
];
});
HTML:
<ul ng-repeat="(key, value) in Reports | groupBy: 'Year'">
{{ key }}
<ul ng-repeat="(key1, value1) in value | groupBy: 'Month'">
<a ng-click="toggleShow(key+key1)"> O{{key1}} </a>
<li ng-repeat="p in value1" ng-if="!showReport[key+key1]">
{{p.Name }}
</li>
</ul>
</ul>
目标是,如果您单击任何带下划线的数字,则属于该月的报告会隐藏或显示(可折叠)。那已经完成了。年份也必须发生这种情况 - 当您单击年份时,必须显示/隐藏其中的月份。我已经尝试了很多东西,但似乎我无法弄清楚我需要什么。我在我的代码所在的位置创建了一个 JS BIN。
http://jsbin.com/huhabehoju/edit?html,js,output
任何帮助将不胜感激。谢谢
【问题讨论】:
标签: javascript angularjs angularjs-ng-repeat ng-repeat