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'}!`,
});
}
上一篇:JavaScript对象属性访问的两种方式


下一篇:JavaScript 对象属性