angular grouping filter

后端 未结 3 1197
独厮守ぢ
独厮守ぢ 2021-01-02 01:35

Following angular.js conditional markup in ng-repeat, I tried to author a custom filter that does grouping. I hit problems regarding object identity and the model being watc

3条回答
  •  醉酒成梦
    2021-01-02 01:57

    You can use groupBy filter of angular.filter module, and do something like this:
    usage: (key, value) in collection | groupBy: 'property'or 'propperty.nested'
    JS:

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

    HTML:

      Group name: {{ key }}
    • player: {{ player.name }}
    热议问题