您的位置:首页 > Web前端 > AngularJS

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

2017-08-16 18:24 253 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  angularjs
相关文章推荐