Answer the question
In order to leave comments, you need to log in
How to make a table from an array using map (React app)?
How in my case to run the output of the table through map
data: [
{'name': 'Education', 'number': 33},
{'name': 'Promotion', 'number': 10},
{'name': 'Events', 'number': 55 }
]
<Table >
<tbody>
//сюда нужно вставить код вывода таблицы
{this.state.data.map(function(row, i) {
return (
<tr key={i}>
{row.map(function(col, j) {
return <td key={j}>{col}</td>;
})}
</tr>
);
})}
</tbody>
</Table>
Answer the question
In order to leave comments, you need to log in
import React, { Component } from 'react'
export default class App extends Component {
render() {
const data = [
{'name': 'Education', 'number': 33},
{'name': 'Promotion', 'number': 10},
{'name': 'Events', 'number': 55 }
]
let tableTemplate;
function makeColumns(row) {
return <td>{row.name} {row.number}</td>
}
tableTemplate = data.map((row, i) => {
return <tr key={i}>{makeColumns(row)}</tr>
})
return (
<table>
<tbody>
{tableTemplate}
</tbody>
</table>
)
}
}
import React, { Component } from 'react'
export default class App extends Component {
render() {
var data = [
{'name': 'Education', 'number': 33},
{'name': 'Promotion', 'number': 10},
{'name': 'Events', 'number': 55 }
];
var tableTemplate;
function makeColumns(row) {
return <td>{row.name} {row.number}</td>
}
tableTemplate = data.map(function(row, i) {
return <tr key={i}>{makeColumns(row)}</tr>
});
return (
<table>
<tbody>
{tableTemplate}
</tbody>
</table>
)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question