繁体   English   中英

我需要访问一个数组里面的一个数组里面的一个项目如何 go 关于它(反应)

[英]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.

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