I'm trying to display a 2d array as a table, but I'm not entirely sure how would I go about this with React. This code currently only outputs the first row, I tried returning 2d arrays as a whole but that didn't work either.
var DisplayRow = React.createClass({
getDefaultProps: function() {
return {
columns: []
};
},
render: function(){
console.log(this.props.columns);
var entries = []
for (var i = 0; i < this.props.columns.length; i++){
return(
<DisplayElement row={this.props.columns[i]} key={i} />
);
};
}
});
var DisplayElement = React.createClass({
getDefaultProps: function(){
return {
row: []
};
},
render: function(){
console.log(this.props.row);
var elements = []
for (var i=0; i < this.props.row.length; i++){
elements.push(<td> {this.props.row[i]} </td>);
}
return (
<tr> {elements} </tr>
)
}
});