Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.contacts = [
- {
- "id": "1",
- "name": "first name",
- "surname": "first surname",
- "age": "29",
- "group": "group 1",
- "description": "This is first",
- "note": "some notification"
- },
- {
- "id": "2",
- "name": "second name",
- "surname": "second surname",
- "age": "27",
- "group": "group 2",
- "description": "This is first",
- "note": "some notification"
- },
- {
- "id": "3",
- "name": "third name",
- "surname": "third surname",
- "age": "25",
- "group": "group 1",
- "description": "This is first user",
- "note": "some notification"
- }]
- $scope.selectGroups = new Set();
- $scope.groups = [];
- var test = [];
- for (var i = 0; i < $scope.contacts.length; i++) {
- $scope.selectGroups.add($scope.contacts[i].group);
- }
- test = JSON.stringify(Array.from($scope.selectGroups));
- $scope.groups = JSON.parse(test);
- $scope.contacts.filter( contact => contact.group === 'group 1' ) //оставит кантакты только из группы 1
- $scope.contacts.sort( (contact1, contact2) => contact.group.localeCompare( contact2.group ) ) //отсортирует контакты по группе.
- $scope.groups = {};
- $scope.selectGroups = new Map();
- for (var i = 0; i < $scope.contacts.length; i++) {
- if (!$scope.selectGroups.has($scope.contacts[i].group)) {
- var users = [];
- $scope.selectGroups.set($scope.contacts[i].group, users);
- $scope.selectGroups.get($scope.contacts[i].group).push($scope.contacts[i].name);
- } else {
- $scope.selectGroups.get($scope.contacts[i].group).push($scope.contacts[i].name);
- }
- }
- $scope.groups = Array.from($scope.selectGroups);
- <div ng-repeat="group in groups">
- {{group[0]}}<br>
- <div ng-repeat="gr in group[1]">
- {{gr}}
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement