我有这段代码:
$scope.GetEmp= function () {
$http.get("/api/emp/GetEmps")
.success(function (data) {
$scope.Emps= data;
hideLoader();
})
.error(function (error) {
$scope.operation_result = { result: false, Message: 'Unable to complete the action due to API problem' };
$scope.show_result = true;
hideLoader();
});
};
该方法返回此: [[" 1"," Elmer Chacon"],[" 2"," Juan Perez"],[" 3&# 34;," Mauricio Lopez"]]
如何使用此类数据填充下拉列表?
提前致谢。
答案 0 :(得分:3)
你可以这样做:
<强> HTML 强>
<div ng-controller="MyCtrl">
<select ng-model="selected">
<option ng-repeat="item in data" value="{{item[0]}}" >{{item[1]}}</option>
</select>
<div>Selected: {{selected}}</div>
</div>
角度控制器:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.data = [["1","Elmer Chacon"],["2","Juan Perez"],["3","Mauricio Lopez"]];
}
您应该使用当前的方法加载数据。
答案 1 :(得分:1)
与Joris的答案类似,但使用ng-options可以做到这样的事情:
<强> HTML:强>
<div ng-controller="MyCtrl">
<select ng-model="selected" ng-options="item[0] as item[1] for item in data"></select>
<div>Selected: {{selected}}</div>
</div>
角度控制器:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.data = [["1","Elmer Chacon"],["2","Juan Perez"],["3","Mauricio Lopez"]];
}