首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用map函数,显示每个都有图像的map元素。

使用map函数,显示每个都有图像的map元素。
EN

Stack Overflow用户
提问于 2021-03-05 14:11:55
回答 1查看 147关注 0票数 0

我试图使用React的map函数来显示地图元素。每个地图元素都有一个图像。如果我查看这个数组,就会看到这个数组中的内容,所以它被填充了。图片采用Base64格式。如果我试图用来自map函数之外的数组的图像来呈现一个普通的图像标记,它就是这样工作的!所以一定是因为地图函数--就在哪里?

代码语言:javascript
运行
复制
    {alleBilder.length &&
    alleBilder.map((bild, index) => {
      <Col md={3} xs={6}>
        <Card className={classes.root}>
          <CardActionArea>
            <img src={bild.bild}></img>
            <CardContent>
              <Typography gutterBottom variant="h5" component="h2">
                Lizard
              </Typography>
              <Typography
                variant="body2"
                color="textSecondary"
                component="p"
              >
                Lizards are a widespread group of squamate reptiles, with
                over 6,000 species, ranging across all continents except
                Antarctica
              </Typography>
            </CardContent>
          </CardActionArea>
          <CardActions style={{ float: "right" }}>
            <IconButton aria-label="add to favorites">
              <FavoriteIcon />
            </IconButton>
          </CardActions>
        </Card>
      </Col>;
    })}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-05 14:24:25

你在搅乱map的回调。您应该从回调中返回jsx,但没有返回任何内容。请看如何在JSX中使用map

.map()

如何在JSX中使用它

代码语言:javascript
运行
复制
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
  <li>{number}</li>
);

相当于:

代码语言:javascript
运行
复制
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
  (<li>{number}</li>)
);

相当于:

代码语言:javascript
运行
复制
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) => {
  return (<li>{number}</li>)
}
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66494061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档