2 回答
TA贡献1934条经验 获得超2个赞
我已经清理了你的代码,所以它应该可以工作。只是地图内的第一个元素需要,key根据您的数据,它可能是数组中的索引位置
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavDropdown">
<ul className="navbar-nav">
{(menus || []).map((item, ix) => (
<li key={ix} className="nav-item active">
<Link
className="nav-link"
to={{
pathname: item.slug,
state: {
pageId: item.slug
}
}}
>
{item.title}
</Link>
{(item.child_items || []).map((childItem, ix) => (
<div key={ix} className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<Link
className="dropdown-item"
to={{
pathname: childItem.slug,
state: {
pageId: childItem.slug
}
}}
>
{childItem.title}
</Link>
</div>
))}
</li>
))}
</ul>
</div>
</nav>
);
TA贡献1794条经验 获得超8个赞
这是我正在寻找的语法和条件
<li className={ item.child_items ? "nav-item dropdown" : "nav-item " }
添加回答
举报