角度组由JSON多个密钥组成

时间:2016-06-23 12:52:16

标签: javascript angularjs json

我正在使用Angular字段groupBy https://github.com/a8m/angular-filter#groupby,它就像一个简单的JSON文件的魅力,但在这里我的问题

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

我希望:

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

但是我的代码是:

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

我的代码与示例相同

<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>

任何帮助都会非常感激, 非常感谢你

1 个答案:

答案 0 :(得分:1)

迭代播放器json中的团队对象,然后将其传递给过滤器bcoz它不接受数组