--- order: 2 title: zh-CN: 只展开当前父级菜单 en-US: Open current submenu only --- ## zh-CN 点击菜单,收起其他展开的所有菜单,保持菜单聚焦简洁。 > 该用法要求 antd@2.0+ ## en-US Click the menu and you will see that all the other menus gets collapsed to keep the entire menu compact. > This demo is for antd@2.0+. ````jsx import { Menu, Icon } from 'antd'; const SubMenu = Menu.SubMenu; const Sider = React.createClass({ getInitialState() { return { current: '1', openKeys: [], }; }, handleClick(e) { console.log('Clicked: ', e); this.setState({ current: e.key }); }, onOpenChange(openKeys) { const state = this.state; const latestOpenKey = openKeys.find(key => !(state.openKeys.indexOf(key) > -1)); const latestCloseKey = state.openKeys.find(key => !(openKeys.indexOf(key) > -1)); let nextOpenKeys = []; if (latestOpenKey) { nextOpenKeys = this.getAncestorKeys(latestOpenKey).concat(latestOpenKey); } if (latestCloseKey) { nextOpenKeys = this.getAncestorKeys(latestCloseKey); } this.setState({ openKeys: nextOpenKeys }); }, getAncestorKeys(key) { const map = { sub3: ['sub2'], }; return map[key] || []; }, render() { return ( Navigation One}> Option 1 Option 2 Option 3 Option 4 Navigation Two}> Option 5 Option 6 Option 7 Option 8 Navigation Three}> Option 9 Option 10 Option 11 Option 12 ); }, }); ReactDOM.render(, mountNode); ````