开发者社区> 问答> 正文

Angular 8读取和过滤JSON数据

我在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))

  }

谁能帮帮我!

展开
收起
1128944438887630 2019-11-29 22:01:47 1359 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Angular从零到一 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载