【发布时间】:2016-11-24 19:45:03
【问题描述】:
我有一个字段,它的值来自服务,我使用 ng-options 在选择字段中显示。但默认情况下,我想显示第一个选项。
HTML
<div class="col-lg-4">
<select class="form-control" id="select" ng-model="$root.customerDetails.traderType"
ng-options="traderTypeObj.description for traderTypeObj in traderTypes track by
traderTypeObj.type">
</select>
</div>
js:
if(results.data.traderTypes.status.code == 200){
for(let i= 0; i< results.data.traderTypes.body.length ; i++ ){
let keyVal = {};
keyVal.type = results.data.traderTypes.body[i].ITTD_TRADER_TYPE_CODE;
keyVal.description = results.data.traderTypes.body[i].ITTD_TRADER_TYPE_DESCRIPTION;
$scope.traderTypes.push(keyVal);
}
}
if($rootScope.customerDetails != null &&$rootScope.customerDetails.natureOfBusiness != null && $rootScope.customerDetails.traderType !=
null){
for(let i=0; i < $scope.businessTypes.length ; i++ ){
if($scope.businessTypes[i].description == $rootScope.customerDetails.natureOfBusiness.description){ $rootScope.customerDetails.natureOfBusiness.type =
$scope.businessTypes[i].type;
}
}
for(let i=0; i < $scope.traderTypes.length ; i++ ){
if($scope.traderTypes[i].description == $rootScope.customerDetails.traderType.description){$rootScope.customerDetails.traderType.type = $scope.traderTypes[i].type;
} $rootScope.customerDetails.traderType=$scope.traderTypes[0].description;
}
$scope.$apply();
}}
}
我正在尝试默认显示第一个选项..任何想法
【问题讨论】:
标签: javascript html angularjs select meteor