[英]I need to access an item inside an array inside an array how to go about it (react)
I have a Patient array inside of every patient there is a relatives array inside is an id and a relationship I want to show the relationship based on the id here is an image for the data我在每个病人里面都有一个 Patient 数组里面有一个 relatives 数组是一个 id 和一个关系我想根据 id 显示关系这里是数据的图像
props.data.slice(0, props.n).map((item) => {
return (
<Grid item xl={4} md={4} xs={4}>
<Link to={`/patient/${item.id}`} style={{ textDecoration: 'none', color: theme.palette.text.primary }}>
<Card boxShadow={3} key={item.id} style={{ backgroundColor: theme.palette.card }}>
<CardImg src={item.imgUri} alt={item.name} onError={addDefaultSrc} />
//here I want to show the relationship
</Card>
</Link>
</Grid>
)
}
now to explain it more I have the for every patient a page and there are relative patient section the i render every paitent passed on the rletiveid now i already have the patient id stored now i wont to go throe all the relatives array and find where is == the patient id that i stored and return the relationshop the rletiveid should be unique it means every patient should return one relationshop现在更详细地解释一下,我为每个患者提供了一个页面,并且有相对患者部分,我渲染每个患者传递到 rletiveid 现在我已经存储了患者 ID 现在我不会到 go 查找所有亲属数组并找到在哪里==我存储的患者ID并返回relationshop rletiveid应该是唯一的,这意味着每个患者都应该返回一个relationshop
If your data structure correct as image, this should work如果您的数据结构正确的图像,这应该工作
props.data.slice(0, props.n).map((item) => {
return (
<Grid item xl={4} md={4} xs={4}>
<Link to={`/patient/${item.id}`} style={{ textDecoration: 'none', color: theme.palette.text.primary }}>
<Card boxShadow={3} key={item.id} style={{ backgroundColor: theme.palette.card }}>
<CardImg src={item.imgUri} alt={item.name} onError={addDefaultSrc} />
<p> {item.relatives[1].relationship} </p>
</Card>
</Link>
</Grid>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.