prokject.js
来源:互联网 发布:三菱plc仿真教学软件 编辑:程序博客网 时间:2024/06/06 02:25
var controller1 = function($scope) {
$scope.cart = [{
id: 1243,
name: '西游记',
price: 32.5,
number: 2
},
{
id: 2345,
name: '红楼梦',
price: 32,
number: 4
},
{
id: 4323,
name: '水浒传',
price: 34,
number: 2
},
{
id: 6345,
name: '三国演义',
price: 56,
number: 1
}
];
/**
* 为数量进行减一操作
*/
$scope.reduce = function(id) {
var index = findIndex(id);
if(index != -1) {
--$scope.cart[index].number;
}
}
/**
* 删除一个数据
*/
$scope.remove=function(index){
$scope.cart.splice(index,1);
}
/**
* 减一不得小与1
*/
$scope.$watch('cart',function(newValue,oldValue){
angular.forEach($scope.cart,function(obj,key){
if(obj.number<1){
if(confirm("您确定要删除吗?")){
$scope.cart.splice(key,1);
}else{
$scope.cart[key].number=1;
}
}
});
},true);
/**
* 为数量进行加一操作
*/
$scope.add = function(id) {
var index = findIndex(id);
if(index != -1) {
++$scope.cart[index].number;
}
}
/**
* 计算总价格
*/
$scope.sumPrice = function(){
var sumMoney = 0;
angular.forEach($scope.cart,function(item,key){
sumMoney+=item.number*item.price;
});
return sumMoney;
}
/**
* 按照id查找到一个下标
*/
var findIndex = function(id) {
var index = -1;
angular.forEach($scope.cart, function(item, key) {
if(item.id == id) {
index = key;
return;
}
});
return index;
}
}
$scope.cart = [{
id: 1243,
name: '西游记',
price: 32.5,
number: 2
},
{
id: 2345,
name: '红楼梦',
price: 32,
number: 4
},
{
id: 4323,
name: '水浒传',
price: 34,
number: 2
},
{
id: 6345,
name: '三国演义',
price: 56,
number: 1
}
];
/**
* 为数量进行减一操作
*/
$scope.reduce = function(id) {
var index = findIndex(id);
if(index != -1) {
--$scope.cart[index].number;
}
}
/**
* 删除一个数据
*/
$scope.remove=function(index){
$scope.cart.splice(index,1);
}
/**
* 减一不得小与1
*/
$scope.$watch('cart',function(newValue,oldValue){
angular.forEach($scope.cart,function(obj,key){
if(obj.number<1){
if(confirm("您确定要删除吗?")){
$scope.cart.splice(key,1);
}else{
$scope.cart[key].number=1;
}
}
});
},true);
/**
* 为数量进行加一操作
*/
$scope.add = function(id) {
var index = findIndex(id);
if(index != -1) {
++$scope.cart[index].number;
}
}
/**
* 计算总价格
*/
$scope.sumPrice = function(){
var sumMoney = 0;
angular.forEach($scope.cart,function(item,key){
sumMoney+=item.number*item.price;
});
return sumMoney;
}
/**
* 按照id查找到一个下标
*/
var findIndex = function(id) {
var index = -1;
angular.forEach($scope.cart, function(item, key) {
if(item.id == id) {
index = key;
return;
}
});
return index;
}
}
阅读全文
0 0
- prokject.js
- js
- js
- JS
- JS
- JS
- js
- js
- js
- js
- js
- JS
- js
- JS
- js
- js
- js
- js
- Android6.0 PackageManagerService(PMS)-简介
- AngularJs过滤器
- 动态规划 8.21 体会
- caffe训练自己的数据时的错误
- centos 安装 lnmp 环境
- prokject.js
- Stars--树状数组
- Lintcode 有效的括号序列
- Laravel框架执行流程
- SelectLayout-一个选择放大的Layout
- 输入框自动完成,补全提示代码
- ch2 线性表
- 关于maven package时 检索jdk自带的rt等sun下的class失败解决方案
- 嵌入式应届生毕业六个月后月薪1w4,是什么水平?