如何根据学生人数(计数)使用模型中的数据(角度为1.5)获取每个班级的百分比? 有了这些数据,我必须建立一个代表每个班级的代表图,表示学生与学生总数的百分比。
"payload": {
"Schools": [{
"Sections": [{
"Name": "Class",
"Value": "2A"
}, {
"Name": "Count",
"Value": 29
}
]
}, {
"Sections": [{
"Name": "Class",
"Value": "3C",
}, {
"Name": "Count",
"Value": 31
}]
}, {
"Sections": [{
"Name": "Class",
"Value": "1B",
}, {
"Name": "Count",
"Value": 27
}]
}
],
"masterCategory": "School members",
"totalStudents": 87
}
}
答案 0 :(得分:2)
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records = {
"Schools": [{
"Sections": [{
"Name": "Class",
"Value": "2A"
}, {
"Name": "Count",
"Value": 29
}]
}, {
"Sections": [{
"Name": "Class",
"Value": "3C",
}, {
"Name": "Count",
"Value": 31
}]
}, {
"Sections": [{
"Name": "Class",
"Value": "1B",
}, {
"Name": "Count",
"Value": 27
}]
}],
"masterCategory": "School members",
"totalStudents": 87
}
});

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-repeat="x in records.Schools">{{x.Sections[0].Value}} = {{(x.Sections[1].Value/records.totalStudents)*100 | number : 0}}%</h1>
</body>
</html>
&#13;