【发布时间】:2021-07-20 15:28:51
【问题描述】:
我正在学习 React,遇到了一个对我的关卡来说有点棘手的问题。从我的 API 调用中,我得到一个对象数组的响应。我想提交数据添加一些对象数据。为了了解响应的外观,这是一个示例(它是 JSON 数组)一些数据想要在数组对象数据 {school:"test",schoolId:"2"}
中传播Response
data = [
{0: {name: "tom"}},
{1: {name: "Pope"}},
{2: {name: "jack"}}
];
Response to want send like
data = [
{
name: "tom",
school :"testing",
schoolId:"2"
},
{
name: "Pope",
school :"testing",
schoolId:"2"},
{
name: "jack",
school :"testing",
schoolId:"2"}
];
【问题讨论】:
-
只需在您的数据上使用
.map。data.map(item => ({...wrapper, item}))wherewrapper = { school: 'testing'. schoolOd: 2}
标签: javascript arrays json reactjs