angular select 根据后台传回的1,2在页面显示是否,并默认选中

 
 
ng-model其实是有赋值给select的,只是赋值的方式是一个对象,也就是"value=?number:4?"这样,而option中没有与之对应的值,所以没有被默认选中;
 
 
ng-options用的是as...for...这种形式,将option的value设置为“number:3”这种形式,与ng-model的值的形式是对应的,所以ng-model能找到对应值,因此才选中;
js部分:
$scope.equityStructurelist=$scope.baseInfos.enterpriseEquityStructure;
                $scope.aaa=$scope.baseInfos.enterpriseBasicInfoWithBLOBs.nsnenterpriseflag;
 //后台传回1,2
 $scope.bbb=$scope.baseInfos.enterpriseBasicInfoWithBLOBs.ecgmvflag; //后台传回1,2
 $scope.aObj=[{"id":1,"name":"是"},{"id":2,"name":"否"};  //自定义一个对象

页面部分:
<select name="nsnEnterpriseFlag" id="nsnEnterpriseFlag" class="form-control" ng-model = "aaa" ng-options= "a.id as a.name for a in aObj"></select>
<select name="ecGmvFlag" id="ecGmvFlag" class="form-control" ng-model="bbb" ng-options="b.id as b.name for b in aObj" ></select>













猜你喜欢

转载自blog.csdn.net/czp555/article/details/77262643