• 操作数据(对象对象的格式)


    最终需要的数据格式:

    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 } })

     

  • 相关阅读:
    encog(二)神经网络的训练
    encog(一)
    JAVA基础知识总结14(String、StringBuffer、StringBuilder)
    JAVA基础知识总结13(同步)
    JAVA基础知识总结12(多线程)
    JAVA基础知识总结11(异常)
    JAVA基础知识总结10(包类)
    JAVA基础知识总结9(特殊类)
    JAVA基础知识总结8(设计模式)
    JAVA基础知识总结7(抽象类 | 接口)
  • 原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12658639.html
Copyright © 2020-2023  润新知