ReactJS CoffeScript Rails 4 this.setState 不是函数

ReactJS CoffeScript Rails 4 this.setState is not a function

I.m ReactJS 的新功能,所以经常遇到问题...

所以:

@CommentBox = React.createClass
  getInitialState: ->
    data: []

  componentWillMount: ->
    request_data = null
    val = $.ajax
      url: @props.url
      dataType: 'json'
      success: (data, status, xhr) ->
        request_data = JSON.parse xhr.responseText
        @setState data: request_data
    render: ->
      .......

并在控制台中出现错误:

TypeError: this.setState is not a function
  return this.setState({..

我的回购示例: https://github.com/olegsobchuk/example_app

请帮帮我!

您可能希望使用 => 而不是 -> 作为成功回调,这样 this 就可以引用您的组件:

success: (data, status, xhr) =>