Javascript 在reactjs中的onchange输入中调用2个函数,我会遇到以下错误TypeError:无法读取属性';目标';未定义的
我试图在输入onChange属性中调用两个onChange函数这里是我的代码我的目标是从日期选择器获取日期并通过api发送Javascript 在reactjs中的onchange输入中调用2个函数,我会遇到以下错误TypeError:无法读取属性';目标';未定义的,javascript,reactjs,Javascript,Reactjs,我试图在输入onChange属性中调用两个onChange函数这里是我的代码我的目标是从日期选择器获取日期并通过api发送 constructor(props) { super(props); this.state = { date: '', }; this.onChange = this.onChange.bind(this); this.onDateChange = this.onDateChange.bind(this); this.twoCalls = this.twoCall
constructor(props) {
super(props);
this.state = {
date: '',
};
this.onChange = this.onChange.bind(this);
this.onDateChange = this.onDateChange.bind(this);
this.twoCalls = this.twoCalls.bind(this);}
onDateChange(date, dateString) {
console.log(date, dateString);
}
onChange(e) {
this.setState({ [e.target.name]: e.target.value });
}
twoCalls = e => {
this.onDateChange()
this.onChange()
}
render(){
return(
<div>
<DatePicker
id="date"
placeholder="Date"
name="date"
className="form-control"
required
autocomplete="off"
onChange={this.twoCalls} /> //here is the problem
</div>
)}
您需要将
事件
(日期)传递给两个处理程序。另外,onDateChange
需要另一个名为dateString
twoCalls = e => {
this.onDateChange(e, dateString/* ? */)
this.onChange(e)
}
您需要将
事件
(日期)传递给两个处理程序。另外,onDateChange
需要另一个名为dateString
twoCalls = e => {
this.onDateChange(e, dateString/* ? */)
this.onChange(e)
}
调用时您没有将事件发送到该方法
您只需调用此.onChange(e)方法即可摆脱此错误。调用时,您不会将事件发送到该方法
您只需调用此.onChange(e)方法即可摆脱此错误。当我尝试此方法时,它表示未定义日期字符串,因为它来自antd设计。当我尝试此方法时,它表示未定义日期字符串,因为它来自antd设计