4.1保存选中规格选项
我们需要将用户选中的选项保存在 tb_goods_desc 表的 specification_items 字段中,定义 json
格式如下:
1 |
|
(1)在 baseController.js 增加代码
//从集合中按照 key 查询对象
$scope.searchObjectByKey=function(list,key,keyValue){
for(var i=0;i<list.length;i++){
if(list[i][key]==keyValue){
}
}
}
2)在 goodsController.js 增加代码
$scope.entity={ goodsDesc:{itemImages:[],specificationItems:[]} };
$scope.updateSpecAttribute=function($event,name,value){
var object= $scope.searchObjectByKey(
$scope.entity.goodsDesc.specificationItems ,'attributeName', name);
if(object!=null){ if($event.target.checked ){
object.attributeValue.push(value);
}else{//取消勾选
object.attributeValue.splice( object.attributeValue.indexOf(value ) ,1);//移除选
项
//如果选项都取消了,将此条记录移除
if(object.attributeValue.length==0){
$scope.entity.goodsDesc.specificationItems.splice(
$scope.entity.goodsDesc.specificationItems.indexOf(object),1);
}
}
}else{
$scope.entity.goodsDesc.specificationItems.push(
{"attributeName":name,"attributeValue":[value]});
}
}
3)在 goods_edit.html 调用方法
1 |
|
01 02 03 04 05 06 07 08 09 10 11 12 |
|
为了方便测试,我们可以在页面上某个区域临时添加表达式,以便观测测试结果
1 |
|