【发布时间】:2019-06-06 16:16:42
【问题描述】:
我在 angularJS 中有一个下拉菜单定义为:
$scope.Ids = [ {
id : 'ID-100',
name : 'ID-100'
}, {
id : 'ID-200',
name : 'ID-200'
}, {
id : 'ID-300',
name : 'ID-300'
} ];
$scope.Id = $scope.Ids[0];
<select class="custom-select" ng-model="Id" ng-options="choice.name for choice in Ids"></select>
我的要求是从 DB 中动态填充这些 Id。
我有一个调用 DB 的 spring 控制器:
$http({
'url' : '/getIds',
'method' : 'POST',
'headers' : {
'Content-Type' : 'application/json'
},
'params' : data
}).then(function(response) {
$scope.Ids = response.data.Ids;
});
并产生一个列表:
["ID-100", "ID-200", "ID-300"]
0: "ID-100"
1: "ID-200"
2: "ID-300"
我的 $scope.Ids 现在将拥有新列表。我需要将此列表以下拉格式映射到我的$scope.Ids,并让我的下拉列表显示第一条记录。
有人可以就如何实现这一点提出想法吗?
【问题讨论】:
标签: angularjs