Javascript 组件道具/功能在对象中不可访问

Javascript 组件道具/功能在对象中不可访问,javascript,react-redux,Javascript,React Redux,我有一个React/Redux组件,它使用fullcalendar.io呈现日历。在componentDidMount()中创建calendar对象时,它具有我试图操纵的某些属性。例如,calendar对象有一个名为“eventDrop”的变量,当偶数被拖放到新位置时会触发该变量。我试图使用这个函数进行API调用,以使用作为父类的道具传入的方法更新数据库。但是,它不允许我访问此函数中的任何道具,并声明错误消息“SCRIPT5007:无法获取未定义或空引用的属性'updateShift'。它甚至不

我有一个React/Redux组件,它使用fullcalendar.io呈现日历。在componentDidMount()中创建calendar对象时,它具有我试图操纵的某些属性。例如,calendar对象有一个名为“eventDrop”的变量,当偶数被拖放到新位置时会触发该变量。我试图使用这个函数进行API调用,以使用作为父类的道具传入的方法更新数据库。但是,它不允许我访问此函数中的任何道具,并声明错误消息“SCRIPT5007:无法获取未定义或空引用的属性'updateShift'。它甚至不允许我调用组件中的任何函数,声明“SCRIPT438:对象不支持属性或方法'fetchData'

这是我定义道具的父类

export class VolunteerScheduling extends React.Component {
   //Constructor & other functions...


  render() {
    return (
                <Index
                  volunteers={this.props.volunteers}
                  getVolunteer={this.props.getVolunteer}
                  updateShift={this.props.updateShift}
                />
)}
const mapStateToProps = state => ({

  volunteers: selectors.volunteer.getAll(state),
  getVolunteer: selectors.volunteer.getOne(state)
})

const mapDispatchToProps = dispatch => ({
  updateShift: (shift) => dispatch(updateShift(shift))
})
export类扩展React.Component{
//构造函数和其他函数。。。
render(){
返回(
)}
常量mapStateToProps=状态=>({
志愿者:选择器。志愿者。获取所有(状态),
Get志愿者:选择器。志愿者。getOne(状态)
})
const mapDispatchToProps=调度=>({
updateShift:(班次)=>调度(updateShift(班次))
})

当您试图访问以下范围时,请使用箭头功能:

eventDrop:(info) => {
                 // Now you can access this.props or this.state here

                this.props.updateShift(shift)
            }

您可以阅读更多有关这方面的内容

太棒了,谢谢!我对ES6的经验不足正在显现出来
eventDrop:(info) => {
                 // Now you can access this.props or this.state here

                this.props.updateShift(shift)
            }