![](/img/trans.png)
[英]I need to access an item inside an array inside an array how to go about it (react & javascript)
[英]I need to access an item inside an array inside an array how to go about it (react)
我在每個病人里面都有一個 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>
)
}
現在更詳細地解釋一下,我為每個患者提供了一個頁面,並且有相對患者部分,我渲染每個患者傳遞到 rletiveid 現在我已經存儲了患者 ID 現在我不會到 go 查找所有親屬數組並找到在哪里==我存儲的患者ID並返回relationshop rletiveid應該是唯一的,這意味着每個患者都應該返回一個relationshop
如果您的數據結構正確的圖像,這應該工作
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.