0

当数据准备好时,我试图在渲染函数中调用组件,或者返回 null。我不知道为什么,但是 react-rails gem 在这个字符串中返回 Parse Error。源代码如下:

var PlayersData = React.createClass({

  loadDataFromServer: function() {
    console.log("loadDataFromServer");
    $.ajax({
      url: this.props.url,
      dataType: 'json',
      success: function(data) {
        this.setState({data: data});
      }.bind(this),
      error: function(xhr, status, err) {
        console.error(this.props.url, status, err.toString());
      }.bind(this)
    });
  },

  getInitialState: function() {
    console.log("getInitialState");
    return {data: {}};
  },

  componentWillMount: function() {
    console.log("componentWillMount");
    this.loadDataFromServer();
  },

  render: function() {
    console.log("render");
    return (
      {this.state.data ? : <PlayersRepresentation data={this.state.data} /> : null}
    );
  }
});

错误跟踪日志:

Showing /Users/user/Documents/Projects/rails_react/app/views/layouts/application.html.erb where line #12 raised:

Error: Parse Error: Line 30: Unexpected token .
  (in /Users/user/Documents/Projects/rails_react/app/assets/javascripts/components/match_center/players_data.js.jsx)

如何修复它?

4

1 回答 1

0

这个冒号不属于:

 //                 V
 {this.state.data ? : <PlayersRepresentation data={this.state.data} /> : null}

如果删除它,它是否正确解析?

于 2015-06-08T16:25:42.617 回答