黑马程序员技术交流社区

标题: 【郑州校区】品优购电商系统开发第 7 章 四 [打印本页]

作者: 我是楠楠    时间: 2020-5-26 15:12
标题: 【郑州校区】品优购电商系统开发第 7 章 四
【郑州校区】品优购电商系统开发第 7 章 四

2.3 读取商品介绍(富文本编辑器)
修改前端代码 goodsController
[AppleScript] 纯文本查看 复制代码
//查询实体
$scope.findOne=function(){
.................
goodsService.findOne(id).success(
function(response){
$scope.entity= response;
//向富文本编辑器添加商品介绍
editor.html($scope.entity.goodsDesc.introduction);
}
);
}

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

[AppleScript] 纯文本查看 复制代码
//查询实体
$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
[AppleScript] 纯文本查看 复制代码
 //查询实体
$scope.findOne=function(){
.........
goodsService.findOne(id).success(
function(response){
.......................
//显示扩展属性
$scope.entity.goodsDesc.customAttributeItems=
JSON.parse($scope.entity.goodsDesc.customAttributeItems);
}
);
}


经过测试,我们发现扩展属性值并没有读取出来,这是因为与下列代码发生冲突
[AppleScript] 纯文本查看 复制代码
$scope.$watch('entity.goods.typeTemplateId',function(newValue,oldValue){
......
$scope.entity.goodsDesc.customAttributeItems =
JSON.parse($scope.typeTemplate.customAttributeItems);//扩展属性
}

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

[AppleScript] 纯文本查看 复制代码
//监控模板 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);//扩展属性
}
}
);
.......
});







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2