Doapper
Doapper

Reputation: 109

Angular group by JSON multiple key

I am using Angular field groupBy https://github.com/a8m/angular-filter#groupby , it is working like a charm for a simple JSON file but here my problem

$scope.players = [
  {name: 'Gene', team: 'alpha'},
  {name: 'George', team: ['alpha','beta']},
];

I want to have :

  Group name: alpha
    * player: Gene
    * player: George
  Group name: beta
    * player: George

But with my code I have :

  Group name: alpha
    * player: Gene
  Group name: alpha,beta
    * player: George

My code is the same as the example

<ul>
  <li ng-repeat="(key, value) in players | groupBy: 'team'">
    Group name: {{ key }}
    <ul>
      <li ng-repeat="player in value">
        player: {{ player.name }}
      </li>
    </ul>
  </li>
</ul>

Any help would be really appreciated, Thank you very much

Upvotes: 0

Views: 381

Answers (1)

Pankaj Kumar
Pankaj Kumar

Reputation: 881

iterate over the team object inside player json and then pass it to the filter bcoz it does not accept array

Upvotes: 1

Related Questions