[英]Nested map function returns nothing
i'm currently developing a Dashboard in React.js with MUI.我目前正在使用 MUI 在 React.js 中开发仪表板。
I have a list of courses and athletes.我有一份课程和运动员名单。 Every athlete can have multiple course applied for.
每个运动员都可以申请多个课程。 For each applied course i want to display a Card with name of the course and the venue.
对于每个应用课程,我想显示一张带有课程名称和场地的卡片。
When i change filter in courseFound to find and return only the first one it works.当我在 courseFound 中更改过滤器以查找并仅返回第一个它起作用的过滤器时。 But when i have a second map function to map the respecting courses, i'll get a blank site.
但是当我有第二个 map function 到 map 相关课程时,我会得到一个空白站点。
{
athletes.map((athlete, index) => {
if (athlete.courses.length > 0 && courses.length > 0 && venues.length > 0) {
const courseFound = courses.filter(course => course.athletes.find(athleteInArray => athleteInArray === athlete.id));
courseFound.map((course, index) => {
const venue = venues.find(venue => venue.id === course?.venue);
return (
<div key={index}>
<h3 className={classes.header}>{athlete.firstName + ' ' + athlete.lastName}</h3>
<DashboardGridElement key={index} courseName={course!.name} courseVenue={venue!.venueClubName} courseId={course!.id} />
</div>
);
})
}
})
}
The "outer" .map()
operation never returns anything. “外部”
.map()
操作从不返回任何内容。 Perhaps you meant to return the result of the "inner" .map()
operation:也许您打算返回“内部”
.map()
操作的结果:
return courseFound.map((course, index) => {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.