$scope.grade=1;//默认为 1 级
//设置级别
$scope.setGrade=function(value){
$scope.grade=value;
}
//读取列表
$scope.selectList=function(p_entity){
if($scope.grade==1){//如果为 1 级
$scope.entity_1=null;
$scope.entity_2=null;
}
if($scope.grade==2){//如果为 2 级
$scope.entity_1=p_entity;
$scope.entity_2=null;
}
if($scope.grade==3){//如果为 3 级
$scope.entity_2=p_entity;
}
$scope.findByParentId(p_entity.id);
//查询此级下级列表
}
<span ng-if="grade!=3">
<button type="button" class="btn bg-olive btn-xs"
ng-click="setGrade(grade+1);selectList(entity)">查询下级</button>
</span>
<ol class="breadcrumb">
<li><a href="#" ng-click="grade=1;selectList({id:0})">顶级分类列表</a></li>
<li><a href="#" ng-click="grade=2;selectList(entity_1)">{{entity_1.name}}</a></li>
<li><a href="#" ng-click="grade=3;selectList(entity_2)">{{entity_2.name}}</a></li>
</ol>
$scope.parentId=0;//上级 ID
//根据上级 ID 显示下级列表
$scope.findByParentId=function(parentId){
$scope.parentId=parentId;//记住上级 ID
itemCatService.findByParentId(parentId).success(
function(response){
$scope.list=response;
}
);
}
//保存
$scope.save=function(){
var serviceObject;//服务层对象
if($scope.entity.id!=null){//如果有 ID
serviceObject=itemCatService.update( $scope.entity ); //修改
}else{
$scope.entity.parentId=$scope.parentId;//赋予上级 ID
serviceObject=itemCatService.add( $scope.entity );//增加
}
serviceObject.success(
function(response){
if(response.success){
//重新查询
$scope.findByParentId($scope.parentId);//重新加载
}else{
alert(response.message);
}
}
);
}
<div class="modal-body">
<table class="table table-bordered table-striped" width="800px">
<tr>
<td>上级商品分类</td>
<td>
{{entity_1.name}} >> {{entity_2.name}}
</td>
</tr>
<tr>
<td>商品分类名称</td>
<td><input class="form-control" ng-model="entity.name"
placeholder="商品分类名称"> </td>
</tr>
<tr>
<td>类型模板</td>
<td>
<input ng-model="entity.typeId" placeholder="商品类型模板"
class="form-control" type="text"/>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true"
ng-click="save()">保存</button>
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">
关闭</button>
</div>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |