Reactでデータを表示しようとして問題があります。データは、最初に通常のJS関数で計算し、そのテーブルをレンダリングするリアクト時間で準備ができていないです...JSを介してデータを取得した後に反応したレンダリングテーブル
これは、JS関数の呼び出しです:
<script type="text/javascript">
jQuery(document).ready(function(){
derivePairs();
alert(config.pairs.length);
});
</script>
機能がラウンドを決定シミュレートされたサッカーリーグのロビンペア(config.pairsはそれらのグローバル変数)です。これらのペアをReact renderedテーブルに表示したいと思います。
これは、表のレンダリング反応コードです... config.pairsは時間によって空である理由
var Table = React.createClass({
getInitialState: function() {
return {data: this.props.data};
},
render: function() {
var headerComponents = this.generateHeaders(),
rowComponents = this.generateRows();
return (
<table>
<thead>{headerComponents}</thead>
<tbody>{rowComponents}</tbody>
</table>
);
},
generateHeaders: function() {
var cols = this.props.cols; // [{key, label}]
// generate our header (th) cell components
return cols.map(function(colData) {
return <th key={colData.key}>{colData.label}</th>;
});
},
generateRows: function() {
var cols = this.props.cols, // [{key, label}]
data = this.props.data;
alert(this.props.data.length);
var dataMap = this.props.data.map(function(item) {
alert(item.homeTeam);
});
return this.state.data.map(function(item) {
// handle the column data within each row
alert(item);
var cells = cols.map(function(colData) {
alert("test");
console.log(colData);
// colData.key might be "firstName"
return <td> {item[colData.key]} </td>;
});
return <tr key={item.id}> {cells} </tr>;
});
}
});
ReactDOM.render(<Table cols={columns} data={config.pairs}/>, document.getElementById('roundPairs'));
は、今私は理解がレンダリング反応して、私は反応するように、これらの値を渡す方法についていくつかの助けが必要になりますあなたができるなら助けてください...計算されるとき。
この命令は、ReactDOM.render(document.getElementById( 'roundPairs')));アラートの直後(config.pairs.length); –
私はその最初のことをやってみましたが、エラーが出ました: "Uncaught SyntaxError:予期せぬトークン<"どこのレンダリング(<テーブルの抜粋は – Bostjan
なのでjsxの構文で純粋なjavascriptに変換する必要があるからです) –