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);//扩展属性
}
}
);
.......
});