Java之品优购课程讲义_day07(4)

博客主要围绕前端商品信息处理展开,涉及修改前端代码 goodsController 来读取商品介绍,在 goodsController.js 的 dataLogic 方法添加代码处理商品图片列表,将其由字符串转换为 json 集合对象,还对读取商品扩展属性的代码进行了修改。

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

//查询实体

$scope.findOne=function(){

.................

goodsService.findOne(id).success(

function(response){

$scope.entity=  response;

//向富文本编辑器添加商品介绍editor.html($scope.entity.goodsDesc.introduction);

}

);

}

2.1 显示商品图片列表
修改 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.1 读取商品扩展属性
修改 goodsController.js

//查询实体

$scope.findOne=function(){
.........

goodsService.findOne(id).success(

function(response){

.......................

//显示扩展属性

$scope.entity.goodsDesc.customAttributeItems= JSON.parse($scope.entity.goodsDesc.customAttributeItems);

}

);

}
经过测试,我们发现扩展属性值并没有读取
```出来,这是因为与下列代码发生冲突
  ![](https://s1.51cto.com/images/blog/201808/28/8ff813612feb1ac5e8f1cf23957f2400.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
我们读取出来的值被覆盖了,我们需要改写代码, 添加判断,当用户没有传递 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);//扩展属性

}

}

);

.......

});

转载于:https://blog.51cto.com/13517854/2165494

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值