考虑以下因素:
<Sidenav defaultOpenKeys={['2']}>
<Sidenav.Header>
<div style={headerStyles}>Custom Sidenav</div>
</Sidenav.Header>
<Sidenav.Body>
<Nav>
<Nav.Item eventKey="1" active icon={<DashboardIcon />} href="/dashboard">{t('Dashboard')}</Nav.Item>
<Nav.Menu eventKey="2" title={t("Statistic Data")} icon={<MagicIcon />}>
<Nav.Item eventKey="2-2" href="/newplayerstatistic/level">{t('New Player Level Statistic')}</Nav.Item>
<Nav.Item eventKey="2-3" href="/newplayerstatistic/chapter">{t('New Player Chapter Statistic')}</Nav.Item>
<Nav.Item eventKey="2-4" href="/currentplayerstatistic/level">{t('Current Player Level Statistic')}</Nav.Item>
<Nav.Item eventKey="2-4" href="/currentplayerstatistic/chapter">{t('Current Player Chapter Statistic')}</Nav.Item>
</Nav.Menu>
</Nav>
</Sidenav.Body>
</Sidenav>
在 eventKey="1" 中,活动标签叫什么?我如何使它成为有条件的,以便它仅在为真时才有效,即 {condition ? '积极的': ''}。显然它不是一个字符串,我无法设置 active=true/false。
如果我理解正确,并且您使用ractivejs,那么它非常简单:
<Nav.Item eventKey="1" {{#if anyVariable }} active {{/if}} icon={<DashboardIcon />} href="/dashboard">{t('Dashboard')}</Nav.Item>
然后你做类似的事情
ractive.set('anyVariable',true);