如下两段代码如何写可以更简洁,更易读。
if (res.after.temporary.address) {
this.state.travellerInfo.after.temporary.address = { ...res.after.temporary.address, ...this.state.travellerInfo.after.temporary.address };
}
if (res.after.temporary.people) {
this.state.travellerInfo.after.temporary.people = { ...res.after.temporary.people, ...this.state.travellerInfo.after.temporary.people };
}
if (res.after.temporary.stroke) {
this.state.travellerInfo.after.temporary.stroke = { ...res.after.temporary.stroke, ...this.state.travellerInfo.after.temporary.stroke };
}
if (res.after.temporary.take) {
this.state.travellerInfo.after.temporary.take = { ...res.after.temporary.take, ...this.state.travellerInfo.after.temporary.take };
}
Object.entries(res.after.show_items).forEach(([key, value]) => {
if (key === 'people') {
this.state.travellerInfo.after.temporary.people.show = value;
} else if (key === 'address') {
this.state.travellerInfo.after.temporary.address.show = value;
} else if (key === 'take') {
this.state.travellerInfo.after.temporary.take.show = value;
} else if (key === 'stroke') {
this.state.travellerInfo.after.temporary.stroke.show = value;
}
});