为什么我使用 Bootstrap - React 每行都会得到重复的卡片?
我不明白为什么我每行两次得到同一张卡。这就是我所拥有的,遵循引导程序的文档:
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { Card, Row, Col, Container} from 'react-bootstrap';
function Post({post}) {
console.log("procedure:", post.procedure)
return (
<div>
<Row xs={1} md={2} className="row-cols-2" >
{Array.from({ length: 2 }).map((_, idx) => (
<Col style={{ padding: '3rem' }}>
<Card border="success" style={{ textAlign: 'center', width: '40rem', padding: '1rem' }} >
{/* <Card.Img variant="top" src="holder.js/100px160" /> */}
<Card.Body>
<Card.Title>Procedure: {post.procedure}</Card.Title>
<Card.Subtitle className="mb-2 text-primary"><b> Facility: </b> {post.facility.name} - Location: {post.facility.city}, {post.facility.state}
</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b> Patient cost: $</b>{post.patient_cost}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b> Insurance cost: $</b>{post.insurance_cost}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b>Date of procedure: </b>{post.date_of_procedure}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b>Date of invoice: </b>{post.date_of_invoice}</Card.Subtitle>
<Card.Text>
{post.comments}
</Card.Text>
<Card.Link as={Link} to={"/average"}><b>Check Average Cost </b></Card.Link>
<Card.Link href="#"><b>Another Link </b></Card.Link>
</Card.Body>
<Card.Footer>
<small className="text-primary"><b>Posted on: </b>{post.created_at}</small>
</Card.Footer>
</Card>
</Col>
))}
</Row>
</div>
);
}
export default Post;
我尝试添加容器,更改了几次 className,并使用了 .map(),但我仍然每行两次获得相同的卡,而不是每行两张不同的卡。基本上,我想每行有 2 张卡。不确定网格发生了什么。感谢您的帮助。
I could not figure out why I am getting the same card twice per row. This is what I have, following bootstrap's documentation:
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { Card, Row, Col, Container} from 'react-bootstrap';
function Post({post}) {
console.log("procedure:", post.procedure)
return (
<div>
<Row xs={1} md={2} className="row-cols-2" >
{Array.from({ length: 2 }).map((_, idx) => (
<Col style={{ padding: '3rem' }}>
<Card border="success" style={{ textAlign: 'center', width: '40rem', padding: '1rem' }} >
{/* <Card.Img variant="top" src="holder.js/100px160" /> */}
<Card.Body>
<Card.Title>Procedure: {post.procedure}</Card.Title>
<Card.Subtitle className="mb-2 text-primary"><b> Facility: </b> {post.facility.name} - Location: {post.facility.city}, {post.facility.state}
</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b> Patient cost: lt;/b>{post.patient_cost}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b> Insurance cost: lt;/b>{post.insurance_cost}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b>Date of procedure: </b>{post.date_of_procedure}</Card.Subtitle>
<Card.Subtitle className="mb-2 text-primary"><b>Date of invoice: </b>{post.date_of_invoice}</Card.Subtitle>
<Card.Text>
{post.comments}
</Card.Text>
<Card.Link as={Link} to={"/average"}><b>Check Average Cost </b></Card.Link>
<Card.Link href="#"><b>Another Link </b></Card.Link>
</Card.Body>
<Card.Footer>
<small className="text-primary"><b>Posted on: </b>{post.created_at}</small>
</Card.Footer>
</Card>
</Col>
))}
</Row>
</div>
);
}
export default Post;
I tried adding container, changed the className a few times, and played around with the .map(), but I still get the same card twice per row, instead of 2 different cards per row. Basically, I would like to have 2 cards per row. Not sure what is going on with the grid. Appreciate the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,看看这是否对您有帮助。
通过这种结构,您将有 1 行,每个帖子有 2 张卡片。
Ok, let see if this help you.
With this structure you will have 1 row with 2 cards for each post.