reactjs - 如何在反应中将图标添加到来自数据库的键
问题描述
我想添加与来自数据库的每个参数相对应的图标......它用于搜索过滤器......这是代码
render() {
let lugares = Object.keys(this.state.filters).map((key) => {
// this.state.filters_selected
return (
<div className="mb-5 ml-2">
<Row>
{Object.values(this.state.icons).map((clave) => {
console.log(clave)
}
)}
<MDBIcon className='mt-1' icon={this.state.icons} />
<h4 className="ml-1 ">{key}</h4>
<hr className="accent-4 ml-1 mt-1 mr-5 grey lighten-5" style={{ width: "150px" }} />
</Row>
图标是您在上面创建的字典 icons:[{'Vehiculo':'car', 'Inmueble':'home','Muebles':'couch', 'Otros':'circle'}]
并且在过滤器中,我有图标的相同键到达..我该怎么做才能使每个图标都绘制在其相应的键中?
解决方案
假设icons
是包含特定图标的键值对的对象,并且每个key
infilters
都包含每个图标的键,那么您应该可以很简单地icon={this.state.icons}
用icon={this.state.icons.key}
or替换icon={this.state.icons[key]}
。希望这可以帮助。
推荐阅读
- r - dir.create 和 shinyapps.io 的问题
- angular - 我可以在 [style.width] 指令中使用像 'calc' 这样的表达式吗?
- html - 无法访问父 div 角度
- ruby-on-rails - CSS Loader Invalid Options 选项不应在 validateOptions 与 react_rails 应用程序中具有其他属性
- python - 如何在表格的 3 列中的 2 列中将度数转换为弧度?
- bash - Bash 脚本从命令行运行,但不能使用 Launchd
- javascript - 捆绑失败:错误:无法解析模块`react-native/Libraries/StyleSheet/ColorPropType.js`
- amazon-cloudwatch - 如何自动化 Cloud Watch 仪表板。?
- python - 熊猫如何计算列值加起来达到阈值的行数
- wpf - 如何让 Add_PreviewMouseDown 与 2 个窗口和 .Show() 一起工作?