Ich baue ein Sidebar-Menü mit Untermenü-Ebenen, und ich diesen Code über das Menü und die Untermenüs zu bauen:Wie Eigenschaft Aufruf Komponente innerhalb der gleichen Komponente mit ReactJS?
MenüSidebar:
import React from 'react';
import SidebarMenuItem from './SidebarMenuItem';
var menuData = require("./data/menu.json");
class SidebarMenu extends React.Component {
constructor(props)
{
super(props);
this.state = { expanded: true };
};
render() {
return (
<div>
{
menuData.map((item, index) => <SidebarMenuItem id={ index.toString()} key={index.toString()} {...item} />)
}
</div>
);
};
}
export default SidebarMenu;
SidebarMenuItem:
Obwohl ich die Untermenüs auf dem Bildschirm sehen kann, erhalte ich den folgenden Fehler:
Warning: SidebarMenuItem: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop.
Ein weiterer Hinweis, dass etwas falsch ist, ist die Ausgabe der Konsole:
0
1
undefined <-- I was supposed to get 11 and 12 here, as this option has 2 submenus
2
Und schließlich meine menu.JSON Daten:
[
{
"title": "Option1",
"link": "www.google.com",
"icon": "fa-edit"
},
{
"title": "Option2",
"link": "",
"icon": "fa-hello",
"submenu":
[
{
"title": "SubOption2.1",
"link": "wwww.yahoo.com",
"icon": "fa-asterisk"
},
{
"title": "SubOption2.2",
"link": "wwww.tisafe.com",
"icon": "fa-save"
}
]
},
{
"title": "Option3",
"link": "www.mezasoft.com",
"icon": "fa-save"
}
]
Hilfe appreaciated um herauszufinden, was mit meinem Code falsch ist.
hilft können Sie nicht eine Stütze 'Schlüssel' genannt haben. Dieser Name ist für die interne Verwendung reserviert – Giladd