2016-04-20 63 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>