我们正在开发一个Web应用程序,该应用程序为用户提供添加订单项的选项以及一个用于更改价格,数量和描述的选项。将订单项添加到购物车
我们总算让这些完成,我们的工作是在这里:
http://jsfiddle.net/75m7e/2067/
问题出在这里:http://i.giphy.com/3o6EhMulFzJPoXzKms.gif
我的JavaScript如下:
function CartForm($scope) {
$scope.searchInfo = [];
$scope.invoice = {
items: [{
product_name: 'x',
qty: 10,
description: 'item',
cost: 9.95
},
{
product_name: 'y',
qty: 170,
description: 'item',
cost: 8
},
{
product_name: 'z',
qty: 150,
description: 'item',
cost: 7
}],
selectedItem : []
};
$scope.addItem = function() {
$scope.invoice.selectedItem.push({
qty: null,
description: null,
cost: null,
product: null,
total: null
});
};
$scope.removeItem = function(index) {
$scope.invoice.selectedItem.splice(index, 1);
};
$scope.total = function() {
var total = 0;
$scope.invoice.selectedItem.forEach(function(item, index){
total += item.total;
})
return total;
};
$scope.calculateTotal = function(selected, index){
$scope.invoice.selectedItem[index].description = selected.description;
$scope.invoice.selectedItem[index].qty = selected.qty;
$scope.invoice.selectedItem[index].cost = selected.cost;
$scope.invoice.selectedItem[index].product = selected.product;
$scope.invoice.selectedItem[index].total = selected.qty*selected.cost;
};
}
如果您每当用户更改数量,成本和具有相同项目产品n的其他行时,请检查所述URL艾姆也在变化。数量,成本是独一无二的,不应该改变。
我不知道我做了什么错误。
任何人都可以帮助我完成这项工作,提前致谢!
喜只修改了 “$ scope.totalFinel” 名称 –
多了一个代码中添加删除功能 \t \t $ scope.totalFinel(); b'coz它的更新中的购物车总计 –
请在这里看到:更新jsFiddle与您的代码:http://jsfiddle.net/KpKaran/40zr2wt6/2/ –