購物車展示
一個商品的購物車是指用戶手動填寫商品數(shù)量后,能夠顯示該商品的總價格,并且能夠計算整個購物車的總價格。下面是一個小的購物車案例。購物車思路解析1. 獲取用戶購買的所有商品信息,包括商品單價和商品數(shù)量。2
一個商品的購物車是指用戶手動填寫商品數(shù)量后,能夠顯示該商品的總價格,并且能夠計算整個購物車的總價格。下面是一個小的購物車案例。
購物車思路解析
1. 獲取用戶購買的所有商品信息,包括商品單價和商品數(shù)量。
2. 使用表格將商品信息展示出來。
3. 對商品價格進(jìn)行計算,即商品單價乘以商品數(shù)量得到商品小計價格。
4. 計算所有商品的總價,即將所有商品的小計價格相加得到總價。
5. 當(dāng)用戶修改商品數(shù)量時,將修改后的商品數(shù)量保存在數(shù)據(jù)庫中。
6. 商品數(shù)量修改后,重新獲取商品信息并賦值到表格中,再次計算商品價格。
購物車的數(shù)據(jù)庫
在購物車案例中,我們需要使用數(shù)據(jù)庫來存儲商品信息和用戶選擇的數(shù)量。通過數(shù)據(jù)庫可以方便地對商品信息進(jìn)行增刪改查操作。
購買商品菊花茶
假設(shè)我們要購買的商品是菊花茶。我們首先需要獲取菊花茶的單價和數(shù)量,并將其保存在數(shù)據(jù)庫中。
購物車頁面代碼
以下是購物車頁面的代碼:
```javascript
manager window['car'] $('#goodsCarList').ligerGrid({
rowHeight: 40,
columns: [
{ display: '商品id號', name: 'goodsId', align: 'center', width: 90 },//自增id
{ display: '商品名稱', name: 'goodsName', align: 'center', width: 90, type: 'text', editor: { type: 'text' } },
{ display: '商品單價', name: 'sale', align: 'center', width: 90 },
{ display: '商品數(shù)量', name: 'count', width: 100, type: 'int', isNegative: false, editor: { type: 'int' } },
{ display: '商品小計', name: 'saleSum', width: 90, render: function(row){
var saleSum {};
saleSum (row['sale'])*(row['count']);
return saleSum;
}}
],
enabledEdit: true,
data: $.extend(true, {}, CustomersData),
pageSize: 10,
toolbar: {
items: [
{ text: '刪除', icon: 'delete' },
{ text: '修改', icon: 'modify' }
]
},
onAfterEdit: updateCar
});
GetData();
function GetData(){
$.ajax({
type: "POST",
url: '',
error:function(mes){
$('ajax獲取購物車數(shù)據(jù)失??!');
},
success: function (html) {
eval(html);
({ data: CustomersData });
GetSumSale();
}
});
}
function GetSumSale() {
// 計算總價格
}
```
以上代碼中,通過設(shè)置`{ display: '商品數(shù)量', name: 'count', width: 100, type: 'int', isNegative: false, editor: { type: 'int' },`可以修改商品數(shù)量。
數(shù)量修改展示
當(dāng)用戶修改商品數(shù)量時,系統(tǒng)會將修改后的數(shù)量保存在數(shù)據(jù)庫中,并重新獲取商品信息并賦值到表格中,重新計算商品價格。這樣就實現(xiàn)了購物車中商品數(shù)量的修改功能。