【发布时间】:2020-10-05 22:43:11
【问题描述】:
我想用我的事件的开始时间设置我父母的属性之一,但我无法从 function(info) 方法内部访问 this.props。我怎样才能达到我想使用的方法?
eventReceive={function (info) {
this.props.onChangeStartDate(info.start);
}}
onChangeStartDate 是我父母的函数之一,它在父组件中设置约会的开始日期,我想将我刚刚添加到日历中的事件数据作为该函数的参数提供。
我收到以下错误:
无法读取未定义的属性“onChangeAppointment”
感谢您的帮助。
【问题讨论】:
-
将
function (info) {更改为(info) => {,否则this将引用当前函数,而不是存在于该函数之外的this -
嗨,谢谢你的帮助,看起来解决了这个问题,但是现在 info.start 返回未定义,但如果我只输入 function(info){console.log(info.start)} 它完美显示日期。可能是什么问题?
-
不确定,看看传入的内容 - 在函数中
console.log(info)this.props.onChangeStartDate之前执行
标签: javascript reactjs fullcalendar parameter-passing react-props