reactjs - 基于先前值的 ReactJS 表条件样式
问题描述
我有一个使用 Material-UI Table 组件的 React JS 应用程序,如下所示:
我需要更改同一日期的最后一行和另一个日期的第一行之间的边框样式,例如 betweenDate A
和Date B
这样:
我创建表格的代码只是一张法线贴图:
<TableCell>
<Typography style={{ fontSize: 16 }}>{new Date(row.date).toLocaleDateString().slice(0, 10)}</Typography>
</TableCell>
<TableCell><Typography noWrap={true} style={{ fontSize: 16 }}>{row.user}</Typography></TableCell>
<TableCell><Typography style={{ fontSize: 16 }}>{row.duration}h</Typography></TableCell>
<TableCell><Typography style={{ fontSize: 16 }}>{row.description}</Typography></TableCell>
<TableCell style={{ width: 35 }} align="left">
<IconButton
className={classes.iconButton}
style={{ marginRight: 3 }}
onClick={() => openWorklogModalForEdit(row.id, row.date, row.duration, row.description, row.project_id, row.user_id, row.project, row.clientName)}>
<EditIcon className={classes.actionsButtonIcon} />
</IconButton>
</TableCell>
<TableCell style={{ width: 65 }} align="right" >
<IconButton
className={classes.iconButton}
onClick={() => deleteWorklog(row.id)}>
<DeleteIcon className={classes.actionsButtonIcon} />
</IconButton>
</TableCell>
</TableRow>
感谢您的时间!
解决方案
通过应用映射,您可以像这样添加检查
rows.map((row,index)=>{
if(index !== 0)?
<td className={row.date === rows[index-1].date? 'blackLine' : 'orangeLine'} </td>
:
<td className='black'} ></td>
})
推荐阅读
- jvm - g1 是否收集年轻 gc 中的所有(伊甸园和幸存者)或部分垃圾?
- r - XGBoost 不使用 Windows 下可用的最大内核数?
- python-3.x - GTK3、SVG 和 Cairo 小部件获得 gtk-missing-image 图标覆盖
- c - 二叉树节点和与父节点的关系
- keras - 如何确定不平衡数据集的 class_weights
- react-native - 如何为 react-native-video 构建自定义搜索栏
- c# - 将字符串反序列化为 *.proto 中定义的对象时出错?
- ios - 找不到框架 .xcframework
- roku - 附加到字符串/文本的正确语法
- regex - 正则表达式直到遇到 > 不跟随大写字符