2 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
e.target.name是company.position,您不能設(shè)置嵌套屬性,例如obj["company.position"],您必須將其拆分:
<input
name="company.position"
type="text"
onChange={e => functions.setData(e)}
value={data.company.position}
/>;
const handleStateChange = e => {
e.preventDefault();
const [section, key] = e.target.name.split(".");
// section is : company
// key is : position
if (key) {
// if you have nested keys to update
setValues({
...form,
[section]: {
...form[section],
[key]: e.target.value
}
});
} else {
// if you're updating on the first level
setValues({
...form,
[section]: e.target.value
});
}
};

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
const nested = e.target.name.split(".");
const [section, key] = nested;
if(nested.length > 2){
let total = nested.length;
let ultimo = nested[total-1];
saveclinicHistory({
...clinicHistory,
[section]: {//patient
...clinicHistory[section],
[key]: {//address
...clinicHistory[section][key],
[ultimo]:e.target.value
}
}
});
添加回答
舉報(bào)