//加载默认 SKU
$scope.loadSku=function(){
$scope.sku=skuList[0];
$scope.specificationItems= JSON.parse(JSON.stringify($scope.sku.spec)) ;
}
<body ng-app="pinyougou" ng-controller="itemController" ng-init="num=1;loadSku()">
<div class="sku-name"><h4>{{sku.title}}</h4></div>
<div class="summary-wrap">
<div class="fl title"><i>价 格</i></div>
<div class="fl price"><i>¥</i> <em>{{sku.price}}</em> <span>降价通知</span></div>
</div>
//匹配两个对象
matchObject=function(map1,map2){ for(var k in map1){
if(map1[k]!=map2[k]){ return false;
}
}
for(var k in map2){
if(map2[k]!=map1[k]){ return false;
}
}
return true;
}
//查询 SKU
searchSku=function(){
for(var i=0;i<skuList.length;i++ ){
if( matchObject(skuList.spec ,$scope.specificationItems ) ){
$scope.sku=skuList; return ;
}
}
$scope.sku={id:0,title:'--------',price:0};//如果没有匹配的
}
//用户选择规格
$scope.selectSpecification=function(name,value){
$scope.specificationItems[name]=value;
searchSku();//读取 sku
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |