javascript - 将数组传递给 React 组件,然后在子组件中访问该数组中的值
问题描述
使用 React(但我认为问题是 Javascript),我试图将数组传递给 React 组件,然后在子组件(消耗数组)中 - 从数组中取出值。
我想要做的是访问我的数组中的值:“_label”。我试过做各种版本的东西,比如:key._label
但没有成功!
家长:
<StyledHorizontalAttributes>
{objects[0].attributeCollection.questions.map((question) => (
<FirstRepeatAttributeLabelAssistant key={question.key} />
))}
{console.log(objects[0].attributeCollection.questions)} // returns [StringAttributeModel (below)]
</StyledHorizontalAttributes>
孩子:
const FirstRepeatAttributeLabelAssistant = ({ label, assistant, key }) => {
return (
<StyledGroup
as={Row}
>
<StyledLabelWrapper>label</StyledLabelWrapper>
{/* {isGroupedInput && ( */}
<Column
size={12}
/>
<Column>
<StyledAssistantWrapper>assistant</StyledAssistantWrapper>
</Column>
</StyledGroup>
);
};
大批:
解决方案
于忘记传递label
给子组件:
<FirstRepeatAttributeLabelAssistant key={question.key} label={question._label} />
并{}
用于从中获取价值label
:
<StyledLabelWrapper>{label}</StyledLabelWrapper>
推荐阅读
- git - 如何从 Git 中删除用户名
- python - BeautifulSoup 查找所有具有类的元素并替换每个值,然后打印加入的新列表
- javascript - 链接不使用“react-router-dom”提供任何输出
- django - unique=True give 已经存在!即使交换 2 个对象的值
- swift - 有没有办法让 Swift for 循环引用外部变量?
- python - 查找两个 csv 文件之间的共同值
- java - 谁在功能接口中实现“其他方法” - 在哪里?
- quarkus - Quarkus 强化指南,如 CIS 或 STIG
- hashicorp-vault - 给定 Vault 中的路径,我如何找到可以访问它的人?
- reactjs - React - 用户登录和令牌验证