React中的阵列循环的响应值
我想根据响应的值显示颜色。 来自响应的数据>
如果优先级很高,则卡颜色为红色,并且优先级低的卡颜色将为绿色
<a style={{ background: 'red' }}>{el.priority}</a>
我将如何实现:
{el.priority.high}
{el.priority.low}
{el.priority.mild}
{el.priority.blocker}
I want to display the color of according to the value from Response.
data from response
If the priority is high, the card color will be red, and if the priority is low the card color will be green
<a style={{ background: 'red' }}>{el.priority}</a>
How I will achieve this:
{el.priority.high}
{el.priority.low}
{el.priority.mild}
{el.priority.blocker}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Aman的答案是正确的。如果
背景
属性不起作用。您可以更具体地使用backgrowdColor
进行操作,并且如果优先级超过2个值,则可以在每种类型上映射颜色,并且使用索引操作员从对象中获取颜色,
即建议使用链接从<<<<代码> react-native 或
@react-navigation/本机
而不是计划锚标签。纯锚标签应仅用于绝对路径。@Aman's answer is correct. In case
background
property doesn't work. You can do it more specifically usingbackgroundColor
And if you have priority more than 2 values you can map color on each type and the use index operator to get color from object i.e
It is recommended to use Link from
react-native
or@react-navigation/native
instead of plan anchor tag. pure anchor tag should be only use for absolute paths.您需要使用条件渲染
You need to use conditional rendering