SHARE
TWEET

Untitled

a guest Apr 21st, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $scope.contacts = [
  2.       {
  3.         "id": "1",
  4.         "name": "first name",
  5.         "surname": "first surname",
  6.         "age": "29",
  7.         "group": "group 1",
  8.         "description": "This is first",
  9.         "note": "some notification"
  10.       },
  11.       {
  12.         "id": "2",
  13.         "name": "second name",
  14.         "surname": "second surname",
  15.         "age": "27",
  16.         "group": "group 2",
  17.         "description": "This is first",
  18.         "note": "some notification"
  19.       },
  20.       {
  21.         "id": "3",
  22.         "name": "third name",
  23.         "surname": "third surname",
  24.         "age": "25",
  25.         "group": "group 1",
  26.         "description": "This is first user",
  27.         "note": "some notification"
  28.       }]
  29.    
  30. $scope.selectGroups = new Set();
  31.         $scope.groups = [];
  32.          var test = [];
  33.  
  34.     for (var i = 0; i < $scope.contacts.length; i++) {
  35.                 $scope.selectGroups.add($scope.contacts[i].group);
  36.             }
  37.  
  38.     test = JSON.stringify(Array.from($scope.selectGroups));
  39.  
  40.     $scope.groups = JSON.parse(test);
  41.    
  42. $scope.contacts.filter( contact => contact.group === 'group 1' ) //оставит кантакты только из группы 1
  43.    
  44. $scope.contacts.sort( (contact1, contact2) => contact.group.localeCompare( contact2.group ) ) //отсортирует контакты по группе.
  45.    
  46. $scope.groups = {};
  47.     $scope.selectGroups = new Map();
  48.  
  49.              for (var i = 0; i < $scope.contacts.length; i++) {
  50.  
  51.  
  52.                  if (!$scope.selectGroups.has($scope.contacts[i].group)) {
  53.                      var users = [];
  54.                      $scope.selectGroups.set($scope.contacts[i].group, users);
  55.  
  56.                         $scope.selectGroups.get($scope.contacts[i].group).push($scope.contacts[i].name);
  57.                     } else {
  58.                         $scope.selectGroups.get($scope.contacts[i].group).push($scope.contacts[i].name);
  59.                     }
  60.  
  61.                 }
  62.  
  63. $scope.groups = Array.from($scope.selectGroups);
  64.    
  65. <div ng-repeat="group in groups">
  66.  
  67.             {{group[0]}}<br>
  68.             <div ng-repeat="gr in group[1]">
  69.                 {{gr}}
  70.             </div>
  71.  
  72.         </div>
RAW Paste Data
Top