【发布时间】:2017-08-15 19:27:19
【问题描述】:
所以我的工作场所在多个地方使用的组件内部使用了 SelectField。说得通。现在,当我在我正在处理的当前组件中使用该组件时。我创建的 onChange 事件没有传递正确完成所需的值。现在,如果我将 SelectField 更改为 onChange={onChange} 它工作正常。但是,它不能这样设置,因为它在应用程序中的其他部分都依赖于它。我是 React 的新手。这是我的功能
addHistory = (field) => (event, index, value, target) => {
const { history } = this.state;
console.log(this.state.history);
console.log(field);
if (field === 'employerName' || field === 'description') {
history[field] = event.target.value;
} else if (field === 'roles') {
history[field] = value;
} else {
history[field] = event.value;
}
this.setState({
history: this.state.history,
});
}
这是我正在导入并与组件一起使用的 CompanySelectField
<CompanySelectField
label={translations.translate('driverProperties', 'typeOfVehicle')}
hint={translations.translate('driverProfile', 'pleaseSelectRole')}
style={{ marginTop: '25px' }}
name={'roles'}
value={this.state.history.roles}
onChange={this.addHistory('roles')}
fullWidth
required
>
这是 CompanySelectField 本身
<SelectField
name={name}
maxHeight={300}
value={value}
onChange={(event, index, response) => onChange(response)}
disabled={disabled}
hintText={hint}
>
提前谢谢你。
【问题讨论】:
-
如果我理解正确,那么像这样更改 SelectField 的 onChange 道具应该可以解决您的问题 => onChange={(event, index, response) => onChange(event, index, response)}
-
完美,谢谢
标签: javascript reactjs material-ui