javascript - Material-UI 多表折叠/展开
问题描述
我正在尝试使用 MateialUI 制作一个可折叠的表格目前,我的幻灯片都有折叠但它们链接到一个“打开”状态,所以如果我打开一张幻灯片,所有其他幻灯片都会打开。
这里是一个 sansbox:https ://codesandbox.io/s/withered-bash-e1mzu?file=/src/components/BrandTable.js
props 对象数组需要为我拥有的每张幻灯片提供一个可折叠的表格。
const props = [
{slide: "Protein", charts: ["Keto"]},
{slide: "Bars with benefits - beyond the nutritional profile", charts: ["Innovative approaches"]},
{slide: "Vegan", charts: []}
]
return (
<div>
{
props.map((blog) =>
<React.Fragment>
<TableRow key={props} >
<TableCell component="th" scope="row">
{blog.slide}
</TableCell>
<TableCell size="small">
<IconButton aria-label="expand row" size="small" onClick={() => setOpen(!open)}>
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon/>}
</IconButton>
</TableCell>
</TableRow>
<TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
<Collapse in={open} timeout="auto" unmountOnExit>
{
open && <Box margin={1}>
<Table size="small" aria-label="purchases">
<TableBody>
{blog.charts}
</TableBody>
</Table>
</Box>
}
</Collapse>
</TableCell>
</TableRow>
}
</React.Fragment>
)
}
</div>
)
}
解决方案
请尝试在此处查看此示例: https ://codesandbox.io/s/kbcee
我认为您可以存储扩展行的活动 ID,而不仅仅是打开/关闭状态。或者,您可以创建Row
每次仅在组件内部使用打开状态的组件。
推荐阅读
- javascript - 在 React 中将 nivo 图表/图表导出为图像
- python - 使用python中的递归解决方案在字符串列表中查找字谜
- gitlab-ci - Is there a better way to disable/skip a job in a GitLab CI pipeline than commenting everything out?
- javascript - How to use @ (at) symbol in package.json in the scripts section (my case: run cucumber-js for tagged features)
- java - spring rest 如何识别新会话?
- sql - PostgreSQL 中的“Information_schema.columns”表下未列出新创建的模式和表
- github - Git rebase 为许多提交添加作者和电子邮件地址
- linux - 获取存储在文件中的变量的值
- android - Google 已压缩您的应用程序。通过大小压缩,某些配置现在在 0MB 大小限制内
- synchronization - perforce p4 与 -x 选项性能