Javascript 循环贴图反应渲染中未定义对象键
我可以像这样访问整个对象Javascript 循环贴图反应渲染中未定义对象键,javascript,reactjs,Javascript,Reactjs,我可以像这样访问整个对象 <Card.Content>{_this.state.index}</Card.Content> {u this.state.index} 它表示不变冲突:对象作为React子对象无效(找到:具有键{name、title、email、phone、photo、officename、manageremail}的对象) 但这不是我的目标,我只是想渲染其中一个关键点 const componentsMobile = this.state.compo
<Card.Content>{_this.state.index}</Card.Content>
{u this.state.index}
它表示不变冲突:对象作为React子对象无效(找到:具有键{name、title、email、phone、photo、officename、manageremail}的对象)
但这不是我的目标,我只是想渲染其中一个关键点
const componentsMobile = this.state.components.map(item => (
<Card fluid key={index}>
<Card.Content>
<Card.Header>{item.value.label}</Card.Header>
</Card.Content>
<Card.Content extra>{_this.state.index.email}</Card.Content>
{/* <Card.Content extra>{_this.state.index.value[item.source]}</Card.Content> */}
</Card>
))
const componentsMobile=this.state.components.map(项=>(
{item.value.label}
{{u this.state.index.email}
{/*{{u this.state.index.value[item.source]}*/}
))
index.cjs.js:798未捕获类型错误:无法读取的属性“email”
未定义
我不知道为什么它是未定义的尝试将检查添加为
\u this.state&&u this.state.index&&u this.state.index.email
如果电子邮件存在,它将显示电子邮件,否则,它将不显示任何内容,此错误也不会出现
从现在起,您可以将解决方案直接放在您正在使用的
\u this.state.index.email
位置。此错误是由于\u this.state.index.email引起的,请您控制一下该值好吗?工作正常!你能详细解释一下为什么在这个例子中_this.state.index没有引起错误吗?我没有你的全部代码,但在组件渲染的早期阶段,你没有状态
中的索引
变量,这将使\u this.state.index
成为未定义的。因此,当JSX试图读取未定义的属性时,它将导致您所面临的问题。