在我的选择值与选项标签中显示的值不同的情况下,我如何获得内部值 例如
<option value="0">Get this value out</option>
答案 0 :(得分:0)
您可以重新构建应用程序以生成选项,而不是尝试提取选项名称,那么它将是微不足道的:
const options = {
'0': 'Get this value out',
'1': 'second value'
}
function submitted(values) {
const name = options[values.mySelect];
console.log(`mySelect option name: ${name}`);
}
const Form = reduxForm({
form: 'example',
onSubmit: submitted
})(props => (
<form onSubmit={props.handleSubmit}>
<select name="mySelect">
{Object.keys(options).map(key => (
<option key={key} value={key}>
{options[key]}
</option>
))}
</select>
<button type="submit">submit</button>
</form>
))