更新状态为ReactJS的对象

时间:2019-02-27 12:46:40

标签: reactjs

我正在尝试更新React应用中的状态

state = {
  pickupAddress: {
    country: '',
    city: '',
    zipCode: '',
    street: '',
  },
  deliveryAddress: {
    country: '',
    city: '',
    zipCode: '',
    street: '',
  },
  parcel: {
    type: '',
    height: '',
    width: '',
    length: '',
    weight: '',
    quantity: '',
  },
};

我面临的问题是,例如,我无法用e.target.pickupAddress.city到达对象内部。 这是我的onChange方法

 onChange = (e) => this.setState({[
    e.target.pickupAddress.country]: e.target.pickupAddress.country
});

0 个答案:

没有答案