1.新增商品
实现商品分类,如下图: 当前显示的是哪一分类的列表,我们就将这个商品分类新增到这个分类下。
实现思路:我们需要一个变量去记住上级 ID,在保存的时候再根据这个 ID 来新增分类
修改 itemCatController.js, 定义变量
$scope.parentId=0;//上级 ID
查询时记录上级 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);
}
}
);
}
修改页面 item_cat.html
上级商品分类
{{entity_1.name}} >> {{entity_2.name}}
商品分类名称
类型模板
保存
关注
打赏
立即登录/注册


微信扫码登录