将参数或者数据当做属性使用

工作日常分享3:今天在工作时候,后端给我提了个奇怪的要求,要求参数当做属性使用,也就是键值对中的键
要求:比如图中的1252参数当做属性使用

"all_gw_qrcode_ids": {
		"1252": {
			"qrcode_parent_id": ["50032", "50031"],
			"qrcode_son_ids": ["60030,60031", "60029,60028"]
		},
		"1253":{
		"qrcode_parent_id": ["50032", "50031"],
		  "qrcode_son_ids": ["60030,60031", "60029,60028"]
	}

在这里插入图片描述
方法:循环的时候将值使用【】框起来使用即可,前提是定义
let param.all_gw_qrcode_ids = {}

let param.all_gw_qrcode_ids = {}

param.all_gw_qrcode_ids = Object.assign(param.all_gw_qrcode_ids, {
          [element.order_product_id]: {
            qrcode_parent_ids: parent,
            qrcode_son_ids: id
          }
        })

在这里插入图片描述

注意事项:如果后端需要的格式或者自己需要的各种需要前面的0,1的时候就使用push方法,push进数组,这个时候定义的变量需要改成数组,如果不需要这个0和1就使用上面的obj合并方法Object.assign()
let param.all_gw_qrcode_ids = 【】

"all_gw_qrcode_ids": {
	0 :{
		"1252": {
		"qrcode_parent_id": ["50032", "50031"],
		"qrcode_son_ids": ["60030,60031", "60029,60028"]
		},
	}

	1:{
	  "1253": {
		"qrcode_parent_id": ["50032", "50031"],
		"qrcode_son_ids": ["60030,60031", "60029,60028"]
		}
	  }

其他工作分享:
统一输入框只能输入数字且不能小于1
使用循环总是拿到最后的值

需要0时
param.all_gw_qrcode_ids.push( {
          [element.order_product_id]: {
            qrcode_parent_ids: parent,
            qrcode_son_ids: id
          }
        })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值