2016-04-20 67 views
4

Im從每個ID的http服務中獲取json值..試圖給出一個下拉列表的名稱和ID作爲存儲的關鍵。如果我有這在我的HTML
在angularjs中選擇鍵/值

<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

你並不需要映射的控制器,你做錯了

嘗試這樣

查看

<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}) ; 

然後你會在你的HTML有這樣的

<select> 
<option ng-repeat="kv in data" value="{{kv.key}}">{{kv.value}}</option> 
</select>