zoukankan      html  css  js  c++  java
  • 操作数据(对象对象的格式)

    最终需要的数据格式:

    goodsinfo :{

      67618:{

        paice:''  "",

        linmitbuy:''  

      },

      67619:{

        paice:''  "",

        linmitbuy:''  

      }

    }

    第一步:

      // 通过下一层页面栈传递过来的信息
      getAssociatedGoodsInfo(itemInfo) {
        const that = this;
        console.log(itemInfo, '获取到了传递过来的商品信息')
        this.setData({
          itemInfo: itemInfo,
          sku_list: JSON.parse(itemInfo.sku_list),
          goods_id: itemInfo.goods_id,
        })
    // 在拿到数据的一瞬间 提前把数据组合成一个数组 方便操作 如下
    // skuListPriceOrNum:[{sku_id:67618,group_price:'',group_limit_buy:''},{sku_id:67619,group_price:'',group_limit_buy:''}]
    //(每遍历一次数组 则自动往数组里面添加一个提前组合好的一个对象  组成数组对象的格式)
        that.data.sku_list.forEach(item => {
          let sku_id = item.sku_id
          let group_price = ''
          let group_limit_buy = ''
          that.data.skuListPriceOrNum.push({
            sku_id,
            group_price,
            group_limit_buy
          })
        })
        let skuAll = {
          group_price: null,
          group_limit_buy: null
        }
        this.data.sku_list.forEach(item => {
          let skuid = item.sku_id;
          this.data.goods_info[skuid] = skuAll
        })
      },
    第二步骤
    // 单个设置拼团活动价格
    // 在这方法单个设置每一个价格 和 数量
    setGroupPrice(e) { const that = this; // console.log(e, '单个设置拼团活动价格') let skuid = e.currentTarget.dataset.skuid that.data.skuListPriceOrNum.forEach(item => { if (item.sku_id == skuid) { item.group_price = e.detail.value } }) that.setData({ skuListPriceOrNum: that.data.skuListPriceOrNum }) },
     // 保存按钮
      saveBtn() {
        let that = this;// group_time: 1
        // group_name: 1
        // group_num: 2
        // goods_id: 10800
        // goods_info[63335][group_price]: 1
        // goods_info[63335][group_limit_buy]: 4
        // goods_info[63336][group_price]: 2
        // goods_info[63336][group_limit_buy]: 5
        // goods_info[63337][group_price]: 3
        // goods_info[63337][group_limit_buy]: 6
    // 在这里最终需要提交数据的时候 生成后台真正所需要的数据格式 (每遍历一次数组 则自动生成一个对象)
    let goods_info = {} that.data.skuListPriceOrNum.forEach(item => { var sku_id = item.sku_id let group_price = item.group_price let group_limit_buy = item.group_limit_buy goods_info[sku_id] = { group_price: group_price, group_limit_buy: group_limit_buy } })

     

  • 相关阅读:
    CSP2019-S2总结
    #期望dp#洛谷 6835 [Cnoi2020]线形生物
    #树状数组,概率,离散,双指针#洛谷 6834 [Cnoi2020]梦原
    #容斥,倍数,排列组合#洛谷 2714 四元组统计
    #莫队,bitset#洛谷 3674 小清新人渣的本愿
    #贪心#洛谷 3173 [HAOI2009]巧克力
    #树链剖分,LCA#洛谷 3398 仓鼠找sugar
    #树状数组,哈希#洛谷 6687 论如何玩转 Excel 表格
    小甲鱼Python第八讲课后习题
    小甲鱼Python第七讲课后习题
  • 原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12658639.html
Copyright © 2011-2022 走看看