【发布时间】:2022-01-10 17:07:03
【问题描述】:
对于我的项目,当我们单击“查看详细信息”按钮时,我试图呈现特定的医生详细信息。就这样——
如何过滤特定的医生数据以将其呈现在 ButtonCl 上的 Card 组件上?目前我正在获取卡片组件的全部数据。在 onClick 事件中,我正在调用导航函数来呈现 Card 组件。因此我无法传输特定医生的数据
这是我的代码—— 路由控制器.js
class RoutingController extends React.Component {
constructor() {
super();
this.state = {
doctorsList: [
{
id: 1,
doctorName: 'Alexis Rodriguez',
speciality: 'PULMONOLOGIST',
ratings: 5,
},
{
id: 2,
doctorName: 'Zeph Gonzales',
speciality: 'GENRAL_PHYSCIAN',
ratings: 5,
},
{
id: 3,
doctorName: 'Virginia Wiggins',
speciality: 'Dentist',
ratings: 4,
}
]
}
}
render() {
return (
<Router>
<Routes>
<Route path="/" element={<Home doctorsList={this.state.doctorsList} />} />
<Route path="/doctordetails" element={<ViewDoctorDetails doctorDetails={this.state.doctorsList} />} />
</Routes>
</Router>
);
}
DoctorListComponent.js
function DoctorListFunctional(props) {
return (
<div className="main-container">
{
props.doctorsListArray.map(doc => {
return <div className="doc-container" key={doc.id}>
<Paper elevation={10} style={paperStyle}>
<Grid align='center'>
<div className="doctor-container">
<h3 align='start'>Doctor Name: <span className="grid-item">{doc.doctorName}</span></h3>
</div>
</Grid>
<Grid align='center'>
<div className="doctor-details-container">
<h5 align='start'>Speciality: <span className="grid-item">{doc.speciality}</span> </h5>
<h5 align='start'>Ratings:<Rating name="read-only" value={doc.ratings} readOnly /></h5>
</div>
</Grid>
<Stack
direction="row"
alignItems="flex-end"
spacing={3}
>
<Button className={classes.MuiButtonControlroot} color='primary' variant='contained' onClick={() => onClick()}>
Book Appointment
</Button>
<Button className={classes.MuiButtonControlroot} color='success' variant='contained' onClick={() => {
navigate("/doctordetails");
}}> **Here due to navigate function, I am not able to filter and transfer the specific doctor data to the next card component**
View Details
</Button>
</Stack>
</Paper>
</div>
})
}
</Grid>
</div>
)
}
ViewDoctorDetailsCardComponent.js
function ViewDoctorDetails(props) {
const navigate = useNavigate();
return (
<div className="main-container">
{
props.doctorDetails.map((doctor => {
console.log(doctor);
return (
<div key={doctor.id}>
{doctor.doctorName}
{doctor.speciality}
{doctor.ratings}
</div>
)
}))
}
【问题讨论】:
-
您想一次只显示一位医生的详细信息吗?
-
是的,我试图显示特定医生的详细信息以查看特定的点击详情
标签: javascript reactjs react-hooks react-router