-2
JSON數據,從Angular JS中的嵌套JSON數據求和?
[
{
"id":1,
"empnumber":"sada",
"photo":"assets/images/59.jpg",
"name":"dummy Nagda",
"designation":" Executive Officer",
"dateofjoining":"15/05/2002",
"location":"India",
"profileDescription":"Lorem ipsum....",
"awards":[
{
"category": "Monthly ",
"points": [
{ "name": "First Appreciation", "score": 50 , "Reason":"Lorem ipsum..."},
{ "name": "Second Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Third Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Fourth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Fifth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Sixth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Reward",
"points": [
{ "name": "Work of Arrk Award", "score": 79 , "Reason":"Lorem ipsum..." },
{ "name": "Masterpiece Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Arrk Ambassador Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Ace Tech Arrkitect Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Star of Support Award", "score": 84 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Training",
"points": [
{ "name": "Self enhancement", "score": 97 , "Reason":"Lorem ipsum..." },
{ "name": "By Management", "score": 93 , "Reason":"Lorem ipsum..." },
{ "name": "Project Requirement", "score": 93 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Self Initiative",
"points": [
{ "name": "Conducting Training", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Employee Engagment",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Other",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Active Participation in Meetings",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Helpful nature in work related areas",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Active Helping in recruitment",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
}
]
},
{
"id":2,
"empnumber":"sa",
"photo":"assets/images/44.jpg",
"name":"aa Zalkikar",
"designation":"Vice President(Delivery Management)",
"dateofjoining":"12/4/2004",
"location":"India",
"profileDescription":"Lorem ipsum....",
"awards":[
{
"category": "Monthly ",
"points": [
{ "name": "First Appreciation", "score": 50 , "Reason":"Lorem ipsum..."},
{ "name": "Second Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Third Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Fourth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Fifth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." },
{ "name": "Sixth Appreciation", "score": 50 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Reward",
"points": [
{ "name": "Work of Arrk Award", "score": 79 , "Reason":"Lorem ipsum..." },
{ "name": "Masterpiece Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Arrk Ambassador Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Ace Tech Arrkitect Award", "score": 84 , "Reason":"Lorem ipsum..." },
{ "name": "Star of Support Award", "score": 84 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Training",
"points": [
{ "name": "Self enhancement", "score": 97 , "Reason":"Lorem ipsum..." },
{ "name": "By Management", "score": 93 , "Reason":"Lorem ipsum..." },
{ "name": "Project Requirement", "score": 93 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Self Initiative",
"points": [
{ "name": "Conducting Training", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Employee Engagment",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Other",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Active Participation in Meetings",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Helpful nature in work related areas",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
},
{
"category": "Active Helping in recruitment",
"points": [
{ "name": "any", "score": 97 , "Reason":"Lorem ipsum..." }
]
}
]
}
]
如何從JSON數據計算所有得分的總和?
我app.js看起來是這樣的,在我所遍歷JSON數據得到的總分,並試圖使用$ scope.sum變量視圖上
var app = angular.module('myApp', []);
app.controller('LeaderboardController', function($scope, $http) {
$http.get("gamify.json")
.success(function (response) {
$scope.names = response;
angular.forEach($scope.names, function(name, mainIndex) {
angular.forEach(name.awards,function(awards,maindemoIndex){
angular.forEach(awards.points,function(point,baseIndex){
$scope.sum+=point.score
});
});
});
}); });
這是我到目前爲止嘗試過的。
環路和添加,有喲你試過什麼? – tymeJV
是的,我已經嘗試循環,但我無法顯示我的HTML中的數據。 –
發佈您到目前爲止嘗試過的方法,以及哪些方法無效。 – tymeJV