javascript - 用选定的属性反应 .map
问题描述
我需要使用具有特定属性的地图显示元素。
我的代码显示所有项目对象的属性。
const {report, info} = this.state;
const max = this.state.info.map((info, index) =>
<DonateReport key={index} title={info.title} opened={info.opened}
onClick={() => this.toggleInfo(index)}>
{report.map(({item}) => ( //<--HERE
<h2 >{item.donaters_count}</h2>
))}
</DonateReport>
);
请告诉我,如何显示具有以下参数的属性:item.month == info.key
也许还有办法解决这个问题......
我真的很感激任何帮助。请不要发誓,我真的在第二天就坐在这个问题上
解决方案
我已经使用ternary operator
并格式化了您的 DonateReport 组件。它应该适合你。让我知道。
<DonateReport key={index} title={info.title} opened={info.opened}
onClick={() => this.toggleInfo(index)}>
{
report.map(item => this.state.info.key === item.month ? //<--HERE
<h2 >{item.donaters_count}</h2>
: null)
}
</DonateReport>
推荐阅读
- wcf - WireMock.net 存根 WCF 服务调用
- r - 使用 lapply 创建带有 x 标签的 ggplot2 直方图
- javascript - 如何在一条路线内获取和发布?
- php - GitHub Actions 错误 SQLSTATE[HY000] [2002] 用于负载测试
- javascript - window.matchMedia 监听器在打印时触发
- fortran - 现代 fortran 中的 sum(sum(A.*B)) (matlab 表示法)
- javascript - JavaScript 获取元素的首字母
- python - python asyncpg TypeError:_execute()得到了一个意外的关键字参数'record_class'
- java - 如何在我的代码中使用三元运算符?
- ios - 使用 CFBundleDocumentTypes 通过 Share Sheet 在我的应用程序上打开图像