我正在尝试使用 React 构建一个下拉菜单。但我无法让它让 onchange 工作。
我尝试了一些方法,但仍然没有成功。数据加载到下拉列表中,当我选择一个时,没有任何变化。
constructor(props) {
super(props);
this.state = {
serviceList: []
};
this.loadData = this.loadData.bind(this);
this.update = this.update.bind(this);
this.delete = this.delete.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e){
this.setState({[e.target.Name]: e.target.value})
}
fillDropdowncus(list){
let result = [];
for (var key in list) {
result.push({ key: list[key]['CusId'] , text: list[key]['CusName'] })
}
return result;
}
<Form.Field>
<label>Select customer</label><br />
<Dropdown selection options={this.fillDropdowncus(this.state.customersList)} onChange={this.handleChange} name="selectCustomer" placeholder='Select Customer' /><br />
</Form.Field>
最佳答案
您的valueChange
应该是handleChange
。
<Dropdown selection options={this.fillDropdowncus(this.state.customersList)} onChange={this.handleChange} name="selectCustomer" placeholder='Select Customer' />
关于javascript - React JS Dropdown onchange 功能不起作用。尝试了几种方法都没有成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56753215/