我有以下mongodb集合。
{
"studCode":"S-110",
"studName":"ABC PQR XYZZ",
"dept":
{
"_id":"83bc3f57-4ef7-51ea-2052-d989541682e f",
"department":
{
"departmentName":"Dept A"
}
}
},
{
"studCode":"S-112",
"studName":"ABC PQR XYZZ",
"dept":
{
"_id":"83bc3f57-4ef7-51ea-2052-d989541682e f",
"department":
{
"departmentName":"Dept B"
}
}
},
{
"studCode":"S-113",
"studName":"शABC PQR XYZZ",
"dept":
{
"_id":"83bc3f57-4ef7-51ea-2052-d989541682e f",
"department":
{
"departmentName":"Dept B"
}
}
},
{
"studCode":"S-114",
"studName":"शABC PQR XYZZ",
"dept":
{
"_id":"83bc3f57-4ef7-51ea-2052-d989541682e f",
"department":
{
"departmentName":"Dept A"
}
}
}
我想在角度js中显示DepartmentNamewise学生详细信息。 喜欢
Dept A:
1) "studCode":"S-114",
"studName":"शABC PQR XYZZ"
2)"studCode":"S-110",
"studName":"ABC PQR XYZZ"
注意:该对象不是来自单个集合。我从不同的集合中收集数据并制作了它的对象,所以不能在mongo中使用group by或类似的东西。 提前谢谢。
答案 0 :(得分:0)
假设您有一组上述对象。您可以使用groupBy
根据部门过滤掉学生的详细信息。
angular.module('app', ['angular.filter']).controller('MainController', function($scope) {
$scope.students = [{
"studCode": "S-110",
"studName": "ABC PQR XYZZ",
"dept": {
"_id": "83bc3f57-4ef7-51ea-2052-d989541682e f",
"department": {
"departmentName": "Dept A"
}
}
}, {
"studCode": "S-112",
"studName": "ABC PQR XYZZ",
"dept": {
"_id": "83bc3f57-4ef7-51ea-2052-d989541682e f",
"department": {
"departmentName": "Dept B"
}
}
}, {
"studCode": "S-113",
"studName": "शABC PQR XYZZ",
"dept": {
"_id": "83bc3f57-4ef7-51ea-2052-d989541682e f",
"department": {
"departmentName": "Dept B"
}
}
}, {
"studCode": "S-114",
"studName": "शABC PQR XYZZ",
"dept": {
"_id": "83bc3f57-4ef7-51ea-2052-d989541682e f",
"department": {
"departmentName": "Dept A"
}
}
}];
});

<!DOCTYPE html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.1/angular-filter.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="description" content="[groupBy and sum example]" />
<meta charset="utf-8">
<title>angular-filter - groupBy and sum example</title>
</head>
<body>
<div ng-controller="MainController">
<ul ng-repeat="(key, value) in students | groupBy: 'dept.department.departmentName'">
<tr>
<th>
{{key}}
</th>
<th>count:{{value.length}}</th>
</tr>
<table class="table table-bordered table-hover table-striped">
<tr data-ng-repeat="student in value">
<td>
{{student.studName}}
</td>
<td>
{{student.studCode}}
</td>
</tr>
</table>
</ul>
</div>
</body>
</html>
&#13;