我在州有以下集合:
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:未定义值
有什么想法吗?
非常感谢
答案 0 :(得分:3)
value
,label
和name
是section
对象的属性,因此您必须像这样访问它:
{this.state.sections.map(function(section) {
return (<Tab key={section.value} title={section.label}>
this.getElementByKey(section.name);
</Tab>);
})}
在您的情况下,您使用了从未定义过的变量(因此是ReferenceError)。