2016-04-20 9 views
4

各IDのhttpサービスからjson値を取得しています。名前とIDのリストを格納するキーとしてドロップダウンしようとしています。私は自分のhtmlでこれを持っている場合は、私のコントローラで anglejsでキー/値を選択

<select> 
<option ng-repeat="(key, value) in data" value="{{key}}">{{value}}</option> 
</select> 


この


$http.get('/api/v1/secure/admin/groups/v/users').success(function(response) { 
    var j=[]; 
    var k=[]; 

    $scope.data=[]; 

    $scope.vId=[]; 
    $scope.vName=[]; 

    console.log(response[0]._id)//getting 1st id 
    console.log(response[0].name.prefix+" "+response[0].name.first+" "+response[0].name.last)//getting name 

    for (var i =0; i<response.length; i++) { 

    k=(response[i]._id); 
    j= (response[i].name.prefix+" "+response[i].name.first+" "+response[i].name.last); 

    console.log("list of visit manager: "+$scope.vManagerName+" id "+$scope.vManagerId); 

    }; 

    $scope.data={ 
    $scope.vManagerId.push(k) : $scope.vManagerName.push(j) 
    } 

}); 

が、その未定義...助けてください..事前に感謝

+0

応答構造は何ですか? –

+0

定義されていないものがあり、応答の構造を記述してください –

答えて

2

はあなたが間違って

この

見るようにしてください行っているとして、あなたのhtmlでこれを持っています

<select ng-model="model" ng-options="d._id as d.name.prefix+' '+d.name.first+' '+d.name.last for d in data"> 
</select> 

CTRL

$scope.data=response 

DEMO

0

ループ内でこれを行うのはなぜですか:

$scope.data.push({"key":k, "value" :j}) ; 

は、その後、あなたはあなたがコントローラ上にマッピングする必要はありません

<select> 
<option ng-repeat="kv in data" value="{{kv.key}}">{{kv.value}}</option> 
</select> 
関連する問題