[英]React fullCalendar, reaching this.props in eventReceive function
I want to set one of my parent's attributes with my event's start time, but I cant reach this.props from inside the function(info) method.我想用我的事件的开始时间设置我父母的属性之一,但我无法从 function(info) 方法内部访问 this.props。 How could I reach tha method I want to use?
我怎样才能达到我想使用的方法?
eventReceive={function (info) {
this.props.onChangeStartDate(info.start);
}}
onChangeStartDate is one of my parent's function which sets the starting date of an appointment in the parent component and I want to give the event's data which I just added in the calendar as a parameter to that function. onChangeStartDate 是我的父函数之一,它在父组件中设置约会的开始日期,我想将刚刚添加到日历中的事件数据作为该函数的参数。
I got the following error:我收到以下错误:
Cannot read property 'onChangeAppointment' of undefined
无法读取未定义的属性“onChangeAppointment”
Thanks for your help.谢谢你的帮助。
The following will solve your error.以下将解决您的错误。
eventReceive={(info) => {
this.props.onChangeStartDate(info.start);
}}
Where () => {}
is an arrow function commonly used.其中
() => {}
是常用的箭头函数。 See documentation .请参阅文档。
The reason the error is occuring is because you losing the context of this inside the scope of the function.发生错误的原因是因为您在函数范围内丢失了 this 的上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.