如何将jsonile Name的唯一值从json绑定到angularjs中的Dropdown

时间:2017-02-17 09:50:20

标签: angularjs-directive angularjs-scope angularjs-ng-repeat

  1. 数组就是这样:

    $ scope.domicile = {}; $ scope.domicile.users = [       {DomicileName:' European',PortFolioName:' nternational Select x EM ADR',Alias:' ADR x EM',Percentage:1.0,Ticker:' ADR',类别:' ADRxEM',SortOrder:1},       {DomicileName:' European',PortFolioName:' International Select x EM ORD',Alias:' Ord x EM',Percentage:4,Ticker:' ORD',类别:' ADRxEM',SortOrder:1},       {DomicileName:' European',PortFolioName:' International Select with EM ADR',Alias:' ADR w EM',Percentage:4,Ticker:' ADR',类别:' ADRwEM',SortOrder:'' },       {DomicileName:'开发市场非欧洲',PortFolioName:'国际选择x EM ADR',Alias:' ADR x EM',百分比:4,Ticker: ' ADR',类别:' ADRxEM',SortOrder:1} ];

  2. enter code here

3 个答案:

答案 0 :(得分:0)

假设您想将数据推送到$scope.fetched = []数组,只需在代码中写下:

$scope.fetched = $scope.domicile.users.filter(function(user) {
    return user.DomicileName === 'European';
});

答案 1 :(得分:0)

$scope.fetched = [];
angular.forEach($scope.domicile.users, function(value, key) {
    if (value["DomicileName"] === "European") {
        $scope.fetched.push($scope.domicile.users[key]); // add to array 
    }
})

答案 2 :(得分:0)

过滤 $ scope.domicile.users 的数据

$scope.domicile = $scope.domicile.users.filter(function(val) { 
    return val['DomicileName'] == 'European' 
});
console.log($scope.domicile);