reactjs - 使用地图反应动态附加
问题描述
我是新来的反应,
我正在学习反应,在这个过程中,我尝试使用反应创建一个 for 循环渲染。我是否被困在以下代码中
下面是我的代码
<Container>
<Row xs={3} md={4} lg={6}>
{[...Array(numberOfCards)].map((e, i) => {
return (
<Col className='mt-5' key={i+1}>
<Card >
{/* <Card.Img top width="100%" src="/images/companylogo.png" alt="Card image cap"/> */}
<Card.Body>
<Card.Title tag="h5">Card title</Card.Title>
<Card.Subtitle tag="h6" className="mb-2 text-muted">Card subtitle</Card.Subtitle>
<Card.Text>Some quick example text to build on the card title and make up the bulk of the
card's
content.</Card.Text>
<Button onClick={() =>addquantity({i+1},{email})}>Button</Button>
</Card.Body>
</Card>
</Col>
)
})}
</Row>
</Container>
在这里,在按钮 Onclick 事件中,我传递了“{i+1}”
你能帮我理解我在这里做错了什么吗?
提前致谢
解决方案
在 中定义函数时onClick
,变量在范围内,不应使用{...}
格式插入。
这应该有效(注意email
应该在某处定义):
<Container>
<Row xs={3} md={4} lg={6}>
{[...Array(numberOfCards)].map((e, i) => {
return (
<Col className='mt-5' key={i+1}>
<Card >
{/* <Card.Img top width="100%" src="/images/companylogo.png" alt="Card image cap"/> */}
<Card.Body>
<Card.Title tag="h5">Card title</Card.Title>
<Card.Subtitle tag="h6" className="mb-2 text-muted">Card subtitle</Card.Subtitle>
<Card.Text>Some quick example text to build on the card title and make up the bulk of the
card's
content.</Card.Text>
<Button onClick={() =>addquantity(i+1,email)}>Button</Button>
</Card.Body>
</Card>
</Col>
)
})}
</Row>
</Container>
推荐阅读
- python - socket.connect_ex 后的套接字 10048 响应
- sql-server - 使用 findstr 将空值替换为 sqlcmd 命令中的空字符串
- python - Django 的 MonthArchiveView 返回“表 'mysql.time_zone' 不存在”
- javascript - 如何使用 Workbox 预缓存渲染的 Django 视图(URL 路由)
- excel - 如何在条件引用单元格的情况下遍历excel自动过滤器
- google-apps-script - 在共享文件上隐藏/显示特定用户的特定表格标签
- sql - 如何选择a列,b列,c列用逗号分隔所有值,d列用逗号分隔所有值,e列选择查询?
- php - 在新库 codeigniter 中加载语言时在 null 上调用成员函数 load()
- azure-active-directory - Azure B2C 实现重定向 404 问题
- ajax - Laravel 数据表 - 未定义函数的错误