React Table Rows Population Issue

- 1 answer

I am trying to generate an html table based on a Rest web service call using React. Only table header was displayed. The table rows are blank. If I debug it, after line

tableModel.rows =  this.state.rows;

tableModel.rows was 'undefined'.

I counldn't figure out what's the issue.

<!DOCTYPE html>
        <title>React Flux</title>
        <script src=""></script>
        <script src=""></script>
        <script src=""></script>
        <div id="container" style="color:red"></div>

        <script type="text/jsx">

            var tableModel = {
               cols: ["id", "name"],
               rows: [],

            var Table = React.createClass({
                getInitialState: function () {
                    return {text: ''};
                componentDidMount: function(){
                        url: "http://localhost:8080/rest/user/findAll"
                    }).then(function(data) {
                            rows: data});
                render: function() {

                    tableModel.rows =  this.state.rows;

                    var _self = this;

                    var thead = React.DOM.thead({},
              (col) {
                       return{}, col);

                    var tbody = (row) {
               (col) {
                           return{}, row[col] || "");
                    return React.DOM.table({}, [thead, tbody]);

            React.render(<Table cols={tableModel.cols} rows={tableModel.rows} />, container);



When your TablesetState, it's render function will be recall, but why do you think it's props would be repopulate? It stay the same, mean Table this.props.rows === []. You could fix it by put the tableModel into Table state and using this.state instead of this.props, or wrap another class to Table to manage data fetching and populate data to Table class.