我在哪里可以在React类中编写条件语句?
我必须写一个有条件的陈述,以使一定百分比的价值绿色,如果其正红色为阴性,则为绿色。但是我不确定在哪里编写此条件语句。
<div>
{this.state.tableData.map((row, index)=>{
return(
<Box component="span" sx={{}}>
<Grid > {row.data.direction}</Grid>
<Grid > ({row.data.marketD}%) today </Grid>
</Box>
)
})}
</div>
我需要制作row.data.marketd
显示颜色。
color: {row.data.marketD}<0 ? 'red':'green'.
但是我不知道要在哪个标签中包含此条件。任何帮助都将受到赞赏。
I have to write a conditional statement to make a certain percentage value green if its positive and red if its negative. But I am not sure where to write this conditional statement.
<div>
{this.state.tableData.map((row, index)=>{
return(
<Box component="span" sx={{}}>
<Grid > {row.data.direction}</Grid>
<Grid > ({row.data.marketD}%) today </Grid>
</Box>
)
})}
</div>
I need to make row.data.marketD
show colour.
color: {row.data.marketD}<0 ? 'red':'green'.
But I have no idea which tag to include this condition in. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将答案视为一个概念。您的UI库可能会提供另一种方式。
Consider the answer as a concept. Your ui library may provide another way.
所有条件陈述都应在实践的正方形内。
All of the condition statement should be inside the square of practice.
另一种方法是将文本包裹在
版式
组件中,并根据条件更改颜色属性。通过这种方式,您将文本与grid
的其余内容内容隔离开来(它不会影响今天
旁边的文本):Another approach is to wrap your text in a
Typography
component and change the color attribute based on your condition. In this way you isolate you text from the rest of the content content of theGrid
(it will not affect thetoday
text beside it):