我正在创建我的应用程序菜单,并且我的功能出现以下错误:
数组或迭代器中的每个子代都应具有唯一的“键”属性
function buildListItemWithNavLink(prop, key, activePro, listItemClasses, whiteFontClasses){
return (
<div>
<NavLink
properties
>
<ListItem button className={classes.itemLink + listItemClasses}>
<ListItemText
properties
/>
</ListItem>
</NavLink>
{prop.subMenus != null ? (
prop.subMenus.map((propSubMenu, keySubMenu) => {
if(propSubMenu.path != undefined)
return buildListItemWithNavLink(propSubMenu, keySubMenu, activePro, listItemClasses, whiteFontClasses);
else
return buildListItemWithoutNavLink(propSubMenu, whiteFontClasses);
})
) : null}
</div>
);
}
我的操作在var中调用:
var links = (
<List className={classes.list}>
{routes.map((prop, key) => {
if (prop.redirect) return null;
var activePro = " ";
var listItemClasses;
listItemClasses = classNames({
[" " + classes[color]]: activeRoute(prop.path)
});
const whiteFontClasses = classNames({
[" " + classes.whiteFont]: activeRoute(prop.path)
});
return buildListItemWithNavLink(prop, key, activePro, listItemClasses, whiteFontClasses);
})}
</List>
);
我不明白问题所在。 我的目标是创建带有子菜单的菜单