我正在尝试使用分页将数组映射到表中。基本上,我需要将数组的元素设置为稍后被映射到单元格中的行,但是我正在尝试的方法不起作用。
我一直试图映射两个变量项目(从父组件传递来的),甚至给它起一个名字。
const columns = [
{ id: 'avtalstyp', label: 'avtalstyp', minWidth: 170 },
{ id: 'bindningstid', label: 'bindningstid', minWidth: 100 },
{ id: 'uppsägningstid', label: 'uppsägningstid', minWidth: 100 },
];
const ProjectList = ( { foretagsnamn, projects } ) => {
const classes = useStyles();
const [page, setPage] = React.useState(0);
const [rowsPerPage, setRowsPerPage] = React.useState(10);
const rows = ({projects})
const handleChangePage = (event, newPage) => {
setPage(newPage);
};
const handleChangeRowsPerPage = event => {
setRowsPerPage(+event.target.value);
setPage(0);
};
return (
<Paper className={classes.root}>
<div className={classes.tableWrapper}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{columns.map(column => (
<TableCell
key={column.id}
align={column.align}
style={{ minWidth: column.minWidth }}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map(row => {
return (
<TableRow hover role="checkbox" tabIndex={-1} key={row.avtalstyp}>
{columns.map(column => {
const value = row[column.id];
return (
<TableCell key={column.id} align={column.align}>
{value}
</TableCell>
);
})}
</TableRow>
);
})}
</TableBody>
</Table>
</div>
<TablePagination
rowsPerPageOptions={[10, 25, 100]}
component="div"
count={rows.length}
rowsPerPage={rowsPerPage}
page={page}
backIconButtonProps={{
'aria-label': 'previous page',
}}
nextIconButtonProps={{
'aria-label': 'next page',
}}
onChangePage={handleChangePage}
onChangeRowsPerPage={handleChangeRowsPerPage}
/>
</Paper>
);
}
export default ProjectList;
const mapStateToProps = state => {
// console.log(state);
return {
projects: state.firestore.ordered.projects,
auth: state.firebase.auth,
profile: state.firebase.profile
};
};