When using getFieldDecorator for two-way form binding, if you set complex default values for the Select selector

getFieldDecorator("bindSelect", {initialValue: getFieldValue("binds").map(item => item.title) })(
    <Select mode="multiple" onDeselect={this.removeBindItem} onSelect={this.selectBindItem} filterOption={false}>
        {this.state.bindItems.map(item => 
            <Select.Option id={item._id} title={item.title} key={item._id} value={item.title}>{item.title}</Select.Option>
        )}
    </Select>
)

Option can set the onDeselect, onSelect, onSearch event of the custom property id, title, code.,Select selector

function(value, option)

complex data objects can be obtained through option. This is great!

however, it can only be a string when setting the default value of Select through the two-way binding of the form.
because the values retrieved by Option in real time may have the same title but different attributes, you want to initialize the values that you want to have in addition to having text,. How do I do that?

Mar.09,2021

1. Although the form binds a value, you can still get the value you need in the select event or the change event
2. You can also construct your value as a combination of several other attributes, such as

value={item.title + ':' + item._id}

value={JSON.stringfy(item)}

2 steps
1.this.setState ({bindItems: data source})
2.form.setFieldsValue ({bindSelect: data source subkey value})

Menu