无法访问回调函数 React 中的属性

Cannot Access Properties in Callback Function React

我正在使用名为 Papa Parse 的库将 csv 文件解析为 json。解析器工作正常,但我无法在 Papa 解析的配置对象的 'complete' 部分中指定的回调函数中调用我的动作创建者。我相信这是一个范围问题,但我一直无法解决它。下面感兴趣的主要部分是为什么我不能调用 'printFile' 函数中的任何一个函数,最重要的是 'addRoster' 函数。请让我知道您有任何建议或想法。谢谢!

编辑:忽略这是片段形式。这里的内容不可运行,我只是无法进行格式化。

class Roster extends Component {

  super(props) {

    this.printFile = this.printFile.bind(this);

    this.testMethod = this.testMethod.bind(this);
  }

  componentWillMount() {
    this.props.addRoster('test')
  }

  printFile(results, file) {
    this.props.addRoster(file);
    this.props.testMethod;
  }

  testMethod(test) {
    console.log("Winner")
  }

  fileDrop(file) {

    var config = {
      delimiter: "", // auto-detect
      newline: "", // auto-detect
      quoteChar: '"',
      header: true,
      dynamicTyping: false,
      preview: 0,
      encoding: "",
      worker: false,
      comments: false,
      step: undefined,
      complete: this.printFile,
      error: undefined,
      download: false,
      skipEmptyLines: false,
      chunk: undefined,
      fastMode: undefined,
      beforeFirstChunk: undefined,
      withCredentials: undefined
    }
    Papa.parse(file, config)
  }


  render() {
    const {
      addRoster
    } = this.props;

    return ( <
      Grid >
      <
      Row >
      <
      MyDropzone onFileDrop = {
        this.fileDrop.bind(this)
      }
      /> < /
      Row > <
      /Grid>
    )
  }

}

export default connect(null, {
  addRoster
})(Roster);

我想你还没有添加构造函数,所以函数没有绑定?尝试改变这个

super(props) 
{
  this.printFile = this.printFile.bind(this);
  this.testMethod = this.testMethod.bind(this);
}

constructor(props) 
{
  super(props);
  this.printFile = this.printFile.bind(this);
  this.testMethod = this.testMethod.bind(this);
}