如何在 reactjs 材料表中加载和映射数据。我正在通过组件将对象传递给子Cards
组件。当控制台日志时,我可以从父级接收对象,但它会抛出failed to compile
错误。谁能让我知道我在哪里犯了错误?
卡片.tsx
function createData(type: any, description: any, volume: any) {
return { type, description, volume };
}
class Card extends Component {
constructor(props: any) {
super(props);
const rows = props.value.cargo;
rows.map((data: any) => {
createData(data.type, data.description, data.volume);
});
}
render() {
return (
<Card className="Card">
<CardContent className="Card-Content">
<Table className="Card-Content__Table">
<TableHead>
<TableRow>
<TableCell>type</TableCell>
<TableCell>description</TableCell>
<TableCell>volume</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map(row => (
<TableRow key={row.volume}>
<TableCell component="th" scope="row">
{row.type}
</TableCell>
<TableCell>{row.description}</TableCell>
<TableCell>{row.volume}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
);
}
}
卡片.tsx
render() {
return (
<div>
{this.state.card.map((card: any) => (
<Card key={card.id} value={card} />
))}
</div>
);
}