javascript - 如何在 react.js 中为变量名添加另一个变量值
问题描述
const healthItemStyle={
backgroundColor:'green'
};
const warningItemStyle={
backgroundColor:'yellow'
};
const errorItemStyle={
backgroundColor:'red'
};
const scenario = ['AppPulse Active','AppPulse Mobile','AppPulse Trace','BSM-Login','Service Portal'];
const scenarioHealth = ['health','warning','health','health','error'];
const items=scenario.map((item,index)=>{
return(
<ListItem style={`${scenarioHealth[index]}ItemStyle`}>
<ListItemText primary={item} secondary={scenarioHealth[index]}/>
</ListItem>
)
});
如上代码所示,我希望能够动态生成标签样式属性的变量名。我已经尝试了很多, ${scenarioHealth[index]}ItemStyle
但显然这不起作用。那请问有什么好的方法吗?
解决方案
推荐阅读
- javascript - 设置 cookie 不出现在 Axios 和 Fetch 中
- perl - 有没有更好的方法在 perl cgi 脚本中提供体面的密码散列?
- vue.js - Nuxt.js(webpack),多个静态文件夹?
- ios - 从firebase调用数据需要完成处理程序?
- sql - 未使用 string_to_array(long_string, ',') 上的 Postgres 功能索引
- python - 无法在 SQL Alchemy 中返回 Postgres 表名
- excel-formula - 从列中的每个单元格中查找日期值,并根据日期在两个日期之间的位置返回年份日期
- c# - 在 TableLayoutPanel 的同一行内的控件内设置控件
- c# - 从位图对象制作更小的位图
- javascript - this.setState 不覆盖旧状态?