我必须将修改后的数据发送到具有json格式的api,如下所示:
{
"Customer": {
"name": "ABC",
"email": ABC@gmail.com,
"password": ""
},
"access": true,
"time": 2000
}
在保存时,我想将相应状态设置为api字段。
save=()=>{
let newCustomer={
access:this.state.access,
time:this.state.time,
name: //How can i set the state values for name,email and
password which is in nested form?
email:
password:
}
return axios.put('api',newCustomer)
.then(response => {
})
}
答案 0 :(得分:1)
您可以像声明json格式一样直接声明它。
let newCustomer={
access:this.state.access,
time:this.state.time,
Customer: {
name: ..., // state name from your nested form
email: ..., // state email from your nested form
password: ..., // state password from your nested form
},
}
答案 1 :(得分:0)
save=(Customer)=>{
let newCustomer={
...Customer,
access: this.state.access,
time: this.state.time,
}
return axios.put('api', newCustomer)
.then(response => {
console.log(response);
})
}
然后newCustomer
会像Customer
一样,但是访问权限和时间可能有所不同。
在后端,您无法访问客户名和电子邮件,就像访问数组一样