Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 循环贴图反应渲染中未定义对象键_Javascript_Reactjs - Fatal编程技术网

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试图读取
未定义的属性时,它将导致您所面临的问题。