繁体   English   中英

我需要访问数组内的一个项目,如何了解它的 go (react & javascript)

[英]I need to access an item inside an array inside an array how to go about it (react & javascript)

我在每个病人里面都有一个 Patient 数组里面有一个 relatives 数组是一个 id 和一个关系我想显示基于 id 的关系这里是数据的图像[![在此处输入图像描述][1]] [1]

 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

您只需要再次对您的亲戚进行 map。

 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} />
                      {item.relatives.map(relative => (<span key={relative.relativeId}>{relative.relationship}</span>))}
                 </Card>
              </Link>
         </Grid>
   )
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM