我正在使用redux表单和材料ui。我有一个表单模板数组,可以选择作为选项。我试图实现的是取回选定的模板,分派一个操作,然后用选定的模板值初始化redux表单。我无法调用SelectItem组件上的方法(控制台中不会记录任何内容)。我也经历过类似的问题和解决办法,但在我的情况下似乎没有任何效果。我的代码是这样的:
setTemplate = (option) => {
console.log(option);}
{formTemplates && (
<Row>
<StyledFormControl>
<Field name="templates" label="Available templates:" component={SelectField}>
<MenuItem value="" disabled>
Choose template:
</MenuItem>
{formTemplates.map(option => {
return (
<MenuItem value={option._id} onClick={this.setTemplate.bind(this, option)} key={option._id}>
{option._id}
</MenuItem>
);
})}
</Field>
</StyledFormControl>
</Row>
)}
你知道为什么这样不行吗?谢谢