007-ant design 对象属性赋值,双向绑定

1、state对象属性赋值

设对象为

state={
 datavalue:{
      id:'',
      name:'',
     },
}

修改对象属性为:

SetName=(e)=>{
      let val=e.target.value;
      let data = Object.assign({}, this.state.datavalue, { name: val })
      this.setState({
        datavalue: data
      })
      console.log(this.state.datavalue,data)
}

2、双向绑定

// 第一个
         {getFieldDecorator('note', {
            rules: [{ required: true, message: 'Please input your note!' }],
          })(
            <Input />
          )}
// 第二个
          {getFieldDecorator('gender', {
            rules: [{ required: true, message: 'Please select your gender!' }],
          })(
            <Select
              placeholder="Select a option and change input text above"
              onChange={this.handleSelectChange}
            >
              <Option value="male">male</Option>
              <Option value="female">female</Option>
            </Select>
          )}

绑定值:

  handleSelectChange = (value) => {
    console.log(value);
    this.props.form.setFieldsValue({
      note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
    });
  }

 

posted @ 2018-08-02 22:42  bjlhx15  阅读(4795)  评论(0编辑  收藏  举报
Copyright ©2011~2020 JD-李宏旭