工作日常分享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
}
})