-1

Array is this and the unique name: DomicileName

$scope.domicile = {};
$scope.domicile.users = [{
    DomicileName: 'European',
    PortFolioName: 'nternational Select x EM ADR',
    Alias: 'ADR x EM',
    Percentage: 1.0,
    Ticker: 'ADR',
    Category: 'ADRxEM',
    SortOrder: 1
}, {
    DomicileName: 'European',
    PortFolioName: 'International Select x EM ORD',
    Alias: 'Ord x EM',
    Percentage: 4,
    Ticker: 'ORD',
    Category: 'ADRxEM',
    SortOrder: 1
}, {
    DomicileName: 'European',
    PortFolioName: 'International Select with EM ADR',
    Alias: 'ADR w EM',
    Percentage: 4,
    Ticker: 'ADR',
    Category: 'ADRwEM',
    SortOrder: ''
}, {
    DomicileName: 'Developed Market Non-European',
    PortFolioName: 'International Select x EM ADR',
    Alias: 'ADR x EM',
    Percentage: 4,
    Ticker: 'ADR',
    Category: 'ADRxEM',
    SortOrder: 1
}];
5
  • So where is your code and what is the problem? Commented Feb 21, 2017 at 9:13
  • i am not able to write a function that filter only unique DomicileName Commented Feb 21, 2017 at 9:15
  • What are you trying to achieve? Commented Feb 21, 2017 at 9:21
  • i want find the distinct DomicileName fron this json and bind these in dropdown Commented Feb 21, 2017 at 9:27
  • Please add your current code to the question. Commented Feb 21, 2017 at 9:28

2 Answers 2

0

angular.module('myApp',[]).controller('MyCtrl', function ($scope) {
    $scope.domicile = {};
    $scope.domicile.users = [{
          DomicileName: 'European',
          PortFolioName: 'nternational Select x EM ADR',
          Alias: 'ADR x EM',
          Percentage: 1.0,
          Ticker: 'ADR',
          Category: 'ADRxEM',
          SortOrder: 1
      }, {
          DomicileName: 'European',
          PortFolioName: 'International Select x EM ORD',
          Alias: 'Ord x EM',
          Percentage: 4,
          Ticker: 'ORD',
          Category: 'ADRxEM',
          SortOrder: 1
      }, {
          DomicileName: 'European',
          PortFolioName: 'International Select with EM ADR',
          Alias: 'ADR w EM',
          Percentage: 4,
          Ticker: 'ADR',
          Category: 'ADRwEM',
          SortOrder: ''
      }, {
          DomicileName: 'Developed Market Non-European',
          PortFolioName: 'International Select x EM ADR',
          Alias: 'ADR x EM',
          Percentage: 4,
          Ticker: 'ADR',
          Category: 'ADRxEM',
          SortOrder: 1
      }];
      
      _init();
      
      function _init() {
      	$scope.domicile.users = _uniq($scope.domicile.users, 'DomicileName')
      }
      
      function _uniq(array, property){
       	var flags = [], output = [], l = array.length, i;
        for( i=0; i<l; i++) {
            if( flags[array[i][property]]) continue;
            flags[array[i][property]] = true;
            output.push(array[i]);
        }
        return output;
      }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="MyCtrl">
    <select>
      <option ng-repeat="user in domicile.users">{{ user.DomicileName }}</option>
    </select>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

for my approach, you have to get the unique values, you can use the modern array function filter, item is the current

    $scope.uniqueDomicileUsers = $scope.domicile.users.filter(function(item, i, ar){
         return ar.indexOf(item) === i; 
    })

you could also check for some property that should be unique, here on the second example, I'm using domicile name

  $scope.uniqueDomicileUsers = $scope.domicile.users.filter(function(item, i, ar){
  return ar.indexOf(item) === i && ar[i]['DomicileName']==item['DomicileName']; 
})

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.