WeChat Mini Programs shopping cart
requests shopping cart data in the app.js, and this.carts = app.globalData.carts in the onLoad on the shopping cart page (cart.wxml).
on the shopping cart page, there are often operations to select, delete, and modify the quantity of an item:
if the first item is selected, modify the quantity of the second item:
this.data.carts[0].selected = true
this.data.carts[1].quantity = 6
send a request to save the modified shopping cart item to the background
wx.request("updateCart", data: {
carts: this.data.carts
},
success: function() {
// Q1
// this.setData({carts:this.data.carts})
// res.data
// this.setData({carts:res.data})
// Q2
// carts"updateCart"
})