2016-11-22 9 views
0

オプションを一覧表示するために選択した角度を使用しています。しかし、ネストされた配列にng-optionsを使用する方法は?ネストされた配列にng-optionsを使用する方法は?

<select chosen 
option="countries" 
ng-model="data" 
    ng-options="??"> 
</select> 

これは私の配列です。

私は、カテゴリ名の嘘で、この
CAT1
アクション1
アクション2
CAT2
action3

action4 CAT3

action5をオプショングループを一覧表示したい
$scope.data= [ 
    { 
"Name": "Cat1", 
"CategoryID": "1", 
"actions": [ 
    { 
    "ActionName": "action1", 
    }, 
    { 
    "ActionName": "action2", 

    } 
] 
}, 
{ 
"Name": "cat 2", 

"actions": [ 
    { 
    "ActionName": "action3", 
    }, 
    { 
    "ActionName": "action4", 

    } 
] 
} 
    { 
"Name": "cat 3", 
"actions": [ 
    { 
    "ActionName": "action5", 
    }, 
    { 
    "ActionName": "actions 5", 

    } 
] 
} 

] 


action6

答えて

0

「データ」を解析し、それを以下の形式に変換して、以下に示すng-optionsを使用できます。

$scope.countries = [ 
    { actionName: 'action1', catName: 'cat1' }, 
    { actionName: 'action2', catName: 'cat1' }, 
    { actionName: 'action3', catName: 'cat2' }, 
    { actionName: 'action4', catName: 'cat2' }, 
    { actionName: 'action5', catName: 'cat3' }, 
    { actionName: 'action6', catName: 'cat3' } 
]; 

<select ng-model="country" 
     ng-options="item.actionName group by item.catName for item in countries"> 
</select> 

私はJavaScriptで新しい配列を作成し、NG-オプションを反復しているhttps://www.undefinednull.com/2014/08/11/a-brief-walk-through-of-the-ng-options-in-angularjs/

0

このリンクでNG-オプションに関する詳細情報を検索し、下のリンク

https://plnkr.co/edit/i9LfV50Y2gXElFzVgFDl?p=preview

をご確認ください

私は配列を作成し、それにすべての値をプッシュしました。

 $scope.uniqueOptions = []; 

for (var i = 0; i < $scope.data.availableOptions.length; i++) 
    $scope.uniqueOptions.push($scope.data.availableOptions[i].Name); 
    //alert($scope.data.availableOptions[i].Name); 
    for (var j = 0; j < $scope.data.availableOptions[i].actions.length; j++) 
    // alert($scope.data.availableOptions[i].actions.length); 
     //alert($scope.data.availableOptions[i].actions[0].ActionName); 
      $scope.uniqueOptions.push($scope.data.availableOptions[i].actions[j].ActionName; 

enter code here 
関連する問題