购物车练习
//下单操作
scope.ordermenu=function(id){
for (var i = 0; i <
scope.ordermenu=function(id){ for (var i = 0; i <
scope.menus.length; i++) {
if(scope.menus[i].id==id){
//销量增加
scope.menus[i].id==id){ //销量增加
scope.menus[i].sells+=$scope.menus[i].number;
break;
}
}
}
//撤销操作
$scope.revmenu=function(id){
if(confirm("确定撤销吗?")){
for (var i = 0; i < $scope.menus.length; i++) {
if($scope.menus[i].id==id){
//销量减少
$scope.menus[i].sells-=$scope.menus[i].number;
//清空数量
$scope.menus[i].number=0;
break;
}
}
}
}
//数量加加 根据id去查询数量,然后再改变它的number值
$scope.increase=function(id){
for (var i = 0; i < $scope.menus.length; i++) {
if($scope.menus[i].id==id){
$scope.menus[i].number++;
break;
}
}
}
//数量的相
$scope.reduce=function(id){
for (var i = 0; i < $scope.menus.length; i++) {
if($scope.menus[i].id==id){
if($scope.menus[i].number==0){
alert("不能再减少了。");
}else{
$scope.menus[i].number--;
}
break;
}
}
}