gpt4 book ai didi

javascript - React JS 尝试映射集合,值未定义

转载 作者:行者123 更新时间:2023-11-28 18:49:39 26 4
gpt4 key购买 nike

我有以下状态集合:

getInitialState: function() {
return {
studentId: 666,
activeTabId: 1,
sections: [
{name: 'were', value: 1, label: 'Basic Details'},
{name: 'ty', value: 2, label: 'Agents Info' },
{name: 'rty', value: 3, label: 'Case Notes'},
{name: 'rtytr', value: 4, label: 'Registration'},
{name: 'rty', value: 5, label: 'Contact Details'},
{name: 'EditStudentAttendance', value: 6, label: 'Attendance'},
{name: 'EditStudentSENDetails', value: 7, label: 'SEN Details'},
{name: 'ewrwer', value: 8, label: 'SEN Reviews'},
{name: 'sdfsd', value: 9, label: 'Assessments'},
{name: 'sdf', value: 10, label: 'Behaviour'},
{name: 'sdfsoood', value: 11, label: 'Detention'},
{name: 'ooo', value: 12, label: 'Achievements'},
{name: 'sdfdsfsdf', value: 13, label: 'Exclusions'},
{name: 'yuui', value: 14, label: 'School History'},
{name: 'uyiu', value: 15, label: 'Documents'}
]
}
},

我正在尝试在渲染中进行映射:

   {this.state.sections.map(function(section) {
return (<Tab key={value} title={label}>
this.getElementByKey(name);
</Tab>);
})}

不断收到错误:

未处理的拒绝ReferenceError:值未定义

有什么想法吗?

非常感谢

最佳答案

valuelabelnamesection 对象的属性,因此您必须像这样访问它:

{this.state.sections.map(function(section) {
return (<Tab key={section.value} title={section.label}>
this.getElementByKey(section.name);
</Tab>);
})}

在您的情况下,您使用了从 undefined variable (因此 ReferenceError)。

关于javascript - React JS 尝试映射集合,值未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34677464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com