概述
前序
今天遇到了一个问题,在数组中push了很多数组,然后想给push进去的数组中对象赋值的时候,发现所有的值都变成了最后一个值,摸不着头脑,找不到原因为什么会这样,后来在同事的帮助先,终于解决了这个问题,现在赖记录一下过程以及解决方法。
arry: [
{
group: "A组",
hcgSchedules: [
{
medicalRecordNum: "bbbbb",
dataTime: "09:00~09:30",
femaleName: "张三aaaa",
femalePhone: "18211234567",
femaleAge: null,
femaleInfertility: null,
eggTime: "09:00:00",
hcgTime: "09:20",
triggerTime: 36,
group: "0",
note: null,
lmp: null,
cycleNumber: null,
cycleType: null,
positiveSign: 0,
},
],
},
{
group: "B组",
hcgSchedules: [
{
medicalRecordNum: "bbbbb",
dataTime: "09:00~09:30",
femaleName: "张三bbb",
femalePhone: "18211234567",
femaleAge: null,
femaleInfertility: null,
eggTime: "09:00:00",
hcgTime: "09:20",
triggerTime: 36,
group: "0",
note: null,
lmp: null,
cycleNumber: null,
cycleType: null,
positiveSign: 0,
},
],
},
{
group: "C组",
hcgSchedules: [
{
medicalRecordNum: "bbbbb",
dataTime: "09:00~09:30",
femaleName: "张三",
femalePhone: "18211234567",
femaleAge: null,
femaleInfertility: null,
eggTime: "09:00:00",
hcgTime: "09:20",
triggerTime: 36,
group: "0",
note: null,
lmp: null,
cycleNumber: null,
cycleType: null,
positiveSign: 0,
},
],
},
],
groupColumns = [
{
title: "",
align: "center",
children: [
{
title: "",
children: [
{
title: "序号",
width: 200,
dataIndex: "key",
key: "key",
},
],
},
{
title: "基本信息",
children: [
{
title: "病历号",
dataIndex: "medicalRecordNum",
key: "medicalRecordNum",
width: 200,
},
{
title: "女方",
dataIndex: "femaleName",
key: "femaleName",
width: 200,
render: (text, record) => {
return (
<span>
{text}
{record.femalePhone}
</span>
)
},
},
{
title: "年龄",
dataIndex: "femaleAge",
key: "femaleAge",
width: 200,
},
],
},
],
},
]
handleColumns = () => {
arry.forEach((item, index) => {
arryColumn.push(groupColumns)
当我这样写的时候,items[0].title的值永远为C组
然后我就在这个位置加上了这行代码
arryColumn = JSON.parse(JSON.stringify(arryColumn))
这样就轻松解决了问题
arryColumn.map((items, i) => {
if (i === index) {
items[0].title = item.group
}
console.log(item.sortedList)
return arryColumn
})
}
最后
以上就是鳗鱼柜子为你收集整理的react中二维数组的赋值问题的全部内容,希望文章能够帮你解决react中二维数组的赋值问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复