我在Angular 8项目中工作,当前的任务是在进入购物篮和支付之前将预订的数据存储到本地存储中,我有眼镜、餐厅和giftCardstypes对象。我将对象存储在localStorage中
[{,…}, {id: 9, designation: "spectacle + restaurant", gift: [], type: "Soirée Bon plan",…},…]
0: {,…}
placesListContent: [{tr_id: "692741", tr_sp_id: "12535", tr_entite: "AG", tr_cat_ordre: "1", tr_cat: "Tarifs :",…}]
0: {tr_id: "692741", tr_sp_id: "12535", tr_entite: "AG", tr_cat_ordre: "1", tr_cat: "Tarifs :",…}
qte: 1
restaurant: null
spectacle: {sp_id: "12535", sp_date: "1563371131", sp_th_id: "1493", sp_cat_id: "3", sp_prod_id: "0",…}
1: {id: 9, designation: "spectacle + restaurant", gift: [], type: "Soirée Bon plan",…}
amount: 60
banner: ""
designation: "spectacle + restaurant"
format: "bb"
gift: []
icon: "/uploads/fe633f32ab883aae44f154f3fead6982.png"
id: 9
qte: 4
type: "Soirée Bon plan"
2: {id: 11, designation: "spectacle + restaurant", gift: [], type: "Soirée Chic",…}
amount: 100
banner: ""
designation: "spectacle + restaurant"
format: "vv"
gift: []
icon: "/uploads/f63473b5694a420ca32fa87f415879a0.png"
id: 11
qte: 2
type: "Soirée Chic"
3: {id: 12, designation: "spectacle + restaurant", gift: [], type: "Soirée VIP",…}
这是giftcardTypes的用户界面: https://i.stack.imgur.com/yaFVd.png
addGiftToCard(type) {
type = type.type
let cardParse = JSON.parse(localStorage.getItem('cart')) || []
let index = _.findIndex(cardParse, item => item.type && item.id == type.id)
if (index == -1) {
type.qte = 1
cardParse.push(type)
} else {
cardParse[index].qte += 1
}
localStorage.setItem('cart', JSON.stringify(cardParse))
}
谁能帮帮我!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。