【发布时间】:2020-05-24 23:00:05
【问题描述】:
我是新手。我想根据某些条件更改表格行。就像我有一个名为 deadLine 的值。因此,如果 deadLine 日期和当前日期之间的差异为 2,则表格行应为绿色,如果差异为 1,则表格行应为黄色,如果为 0 或 -ve,则表格行应为红色。
注意:deadLine 是一个字符串,格式为 dd/MM/yyyy
我如何在反应中实现这一目标?我在 stackOverflow 中看到了一些示例,但没有帮助。
我有这样的代码
<TableBody>
{
this.props.result.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row,i) =>(
<TableRow key={i} >
<TableCell component="th" >
<Typography variant="h4"> {row.a} </Typography>
</TableCell>
<TableCell align="left" > <Typography variant="h4">{row.b}</Typography> </TableCell>
<TableCell align="left" > <Typography variant="h4"> {row.c} </Typography> </TableCell>
<TableCell align="left" > <Typography variant="h4"> {row.d} </Typography> </TableCell>
<TableCell align="left" > <Typography variant="h4"> {row.deadline} </Typography> </TableCell>
</TableRow>
))}
</TableBody>
【问题讨论】: