Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在reactjs中的onchange输入中调用2个函数,我会遇到以下错误TypeError:无法读取属性';目标';未定义的_Javascript_Reactjs - Fatal编程技术网

Javascript 在reactjs中的onchange输入中调用2个函数,我会遇到以下错误TypeError:无法读取属性';目标';未定义的

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

我试图在输入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.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设计