angularjs - calculating a count (number of distinct key's in an object) in angular -


I have the angular code of the following, see below.

What do I want to achieve - for each user - find "count" for each activity type.

What do I want to achieve:

John Thompson = 2 deals
Bill Gates = 3 deals
Billy Wellington = 2 deals, 1 meeting

Activity ID is similar in the object of activity, and $ scope.activities

Bit got stuck here, either how to think about A) Write a function for A or B) NG - Enhance something in HTML element with repeat and group or something.

  $ Scope.competitionDetails = {end_date: "2014-03-01", user: [{id: 2, name: "John Thompson", activities: [[This is all their Activity ID: 6431, Time: (57) .minutes () {}: {ID: 3, Name: "Bill Gates", activities: [[All of their activities ID: (id): (id: 6431) Time: New Date (), Issue: 20}]}, {ID: 6431, Time: New Date), Issue: 20}, {ID: 6431, Time: New Date (), Issue: 20}, {ID: 6431, Time: New Date (), Issue: 20}]}, { Id: 1, Name: "Billy Wellington", activities: [[/ / id: 6432, time: new date): This is their all activity ID: 6431, Time: New Date (), Issue: 20}, {ID : 6431, time: new date}, number: 20}, number: 100}]}]}}; $ Scope.activities = [{id: 6431, name: "deal", number: 20}, {id: 6432, name: "meeting", issue: 100}];  

I have created a bella with an example example for you:

Just using some regular JS, with a small bit of glass:

  // Create a lookup var lookup = {}; Angular.forEach ($ scope.activities, function (activity) {lookup [activity.id] = activity;}); // Calculate the result from angular. ForEach ($ scope.competitionDetails.users, function (user) {user.results = {}; angular.forEach (user.activities, function (activity) {var name = lookup [activity.id] .name; if (! User .results [name]) {user.results [name] = 1;} else {user.results [name] + = 1;}});});  

Comments