angularJS 从后台获取所有分类,并默认选中值(select)

1.html

<select name="parentColumnId" id="selectId" ng-select="mySelect">
  <option ng-repeat="item in allFL" value="{{item.id}}" ng-selected="item.id==mySelect">{{item.columnName}}</option>
</select>

  select 上设置ng-selected(被选中的值)

  option选项中进行判断 当前的id跟被选中的id是否一致

2.js ===获取所有的分类

$http.get('http://192.168.1.107:8080/healthy/findAllFirstColumn.do')
.success(function(res){
	console.log(res);
	$scope.allFL = res;
}).error(function (err){
	console.log(err);
})

3.===获取当前id的父分类

$http.get('http://192.168.1.107:8080/healthy/findColumnById.do?id='+$routeParams.id)
.success(function(res){
	console.log(res);
	$scope.info = res;
	$scope.mySelect = res.parentColumnId;
}).error(function (err){
	console.log(err);
})

猜你喜欢

转载自www.cnblogs.com/dyy-dida/p/9779213.html