品优购电商系统开发第 7 章 四

2.3 读取商品介绍(富文本编辑器)
修改前端代码 goodsController

//查询实体
$scope.findOne=function(){
.................
goodsService.findOne(id).success(
function(response){
$scope.entity= response;
//向富文本编辑器添加商品介绍
editor.html($scope.entity.goodsDesc.introduction);
}
);
}

2.4 显示商品图片列表
修改 goodsController.js ,在 dataLogic 方法添加代码,将图片列表由字符串转换为 json 集合对象

//查询实体
$scope.findOne=function(){
..............
//如果有 ID,则查询实体
goodsService.findOne(id).success(
function(response){
$scope.entity= response;
//向富文本编辑器添加商品介绍
editor.html($scope.entity.goodsDesc.introduction);
//显示图片列表
$scope.entity.goodsDesc.itemImages=
JSON.parse($scope.entity.goodsDesc.itemImages);
}
);
}

2.5 读取商品扩展属性
修改 goodsController.js

//查询实体
$scope.findOne=function(){
.........
goodsService.findOne(id).success(
function(response){
.......................
//显示扩展属性
$scope.entity.goodsDesc.customAttributeItems=
JSON.parse($scope.entity.goodsDesc.customAttributeItems);
}
);
}

经过测试,我们发现扩展属性值并没有读取出来,这是因为与下列代码发生冲突

$scope.$watch('entity.goods.typeTemplateId',function(newValue,oldValue){
......
$scope.entity.goodsDesc.customAttributeItems =
JSON.parse($scope.typeTemplate.customAttributeItems);//扩展属性
}

我们读取出来的值被覆盖了,我们需要改写代码添加判断,当用户没有传递 id 参数时再执行此逻辑

//监控模板 ID ,读取品牌列表
$scope.$watch('entity.goods.typeTemplateId',function(newValue,oldValue){
//读取品牌列表和扩展属性
typeTemplateService.findOne(newValue).success(
function(response){
.......
//如果没有 ID,则加载模板中的扩展数据
if($location.search()['id']==null){
$scope.entity.goodsDesc.customAttributeItems =
JSON.parse($scope.typeTemplate.customAttributeItems);//扩展属性
}
}
);
.......
});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值