【问题标题】:Why is this nested array not rendered?为什么这个嵌套数组没有渲染?
【发布时间】:2020-07-01 19:03:29
【问题描述】:
我对嵌套对象有疑问。我有一个对象,数组“信息”所在的位置,其中还有另一个名为“financeRounds”的数组。
这是表格部分,我在其中呈现融资轮次。但是为什么当我调用 append() 时它们没有呈现在第二个上。
你知道如何解决这个问题吗?
这是我的经济数据结构:
economyData:{
information: [
{
financeRound: [
{
round: "",
investor: ""
}
]
}
]
这是其余的代码框 => https://codesandbox.io/s/array-problem-1cxx9
【问题讨论】:
标签:
javascript
reactjs
typescript
forms
react-hook-form
【解决方案1】:
你的json结构有问题,请尝试
let temp = {economyData: {
information: [
{
financeRound: [
{
round: "",
investor: ""
}
]
}
]
}
}
console.log(JSON.stringify(temp));
temp.economyData.information.push({financeRound:[{round:"2", investor: "who"}]});
console.log(JSON.stringify(temp));
结果应该是这样的
{"economyData":{"information":[{"financeRound":[{"round":"","investor":""}]}]}}
{"economyData":{"information":[{"financeRound":[{"round":"","investor":""}]},{"financeRound":[{"round":"2","investor":"who"}]}]}}