我們正在開發一個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/ –