【发布时间】:2018-11-14 09:45:58
【问题描述】:
如何在 .map 中为每个 TableRow 添加链接?
*我的错误是 validateDOMNesting(...): cannot appear as a child of "" 我正在使用反应路由器 react-router-dom
如何在Table TableRow的.map的每个循环中添加链接?
import React, { Fragment } from 'react'
import { Paper } from 'material-ui'
import Table from 'material-ui/Table';
import TableBody from 'material-ui/Table/TableBody';
import TableCell from 'material-ui/Table/TableCell';
import TableHead from 'material-ui/Table/TableHead';
import TableRow from 'material-ui/Table/TableRow';
import { connect } from 'react-redux'
// import { Edit, Delete } from '@material-ui/icons'
import { withStyles } from 'material-ui/styles'
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
const drawerWidth = 100;
class Listofbond extends React.Component {
render() {
console.log(this.props);
const { MainProps, classes } = this.props;
return (
<Router>
<Paper>
<Table >
<TableHead>
<TableRow>
<TableCell>Bondame</TableCell>
</TableRow>
</TableHead>
<TableBody>
{[1, 2, 3].map(n => {
return (
<Link to={`/bond/${n}/`} key={n}>
<TableRow>
<TableCell component="th" scope="row">
{n}
</TableCell>
</TableRow>
</Link>
);
})}
</TableBody>
</Table>
</Paper>
</Router>
)
}
}
export default Listofbond;
【问题讨论】:
-
在您的链接上添加父级并尝试一下。例如:/bond/${n}/} key={n}>
{n} -
仍然出错 *我的错误是 validateDOMNesting(...): cannot appear as a child of ""
-
@YamoshiWolverine 你找到解决办法了吗?
标签: reactjs redux react-router material-ui react-router-dom