【问题标题】:ReactJS CoffeScript Rails 4 this.setState is not a functionReactJS CoffeScript Rails 4 this.setState 不是函数
【发布时间】:2015-05-01 23:59:18
【问题描述】:

我是 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

请帮帮我!

【问题讨论】:

    标签: ruby-on-rails coffeescript reactjs


    【解决方案1】:

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

    success: (data, status, xhr) =>
    

    【讨论】:

      猜你喜欢
      • 2020-09-08
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      相关资源
      最近更新 更多