我们需要返回上级列表,需要通过点击面包屑来实现
修改itemCatController.js
当为grade=1级,珠宝 为null,银饰 为null。
$scope.entity_1=null;
$scope.entity_2=null;
当为grade=2级,珠宝 有值,银饰 为null。
$scope.entity_1=entity;
$scope.entity_2=null;
当为grade=3级,珠宝 有值,银饰 有值。
$scope.entity_2=entity;
$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>
这里我们使用了ng-if指令,用于条件判断,当级别不等于3的时候才显示“查询下级”按钮
绑定面包屑:
<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>