Skip to content

Instantly share code, notes, and snippets.

@XiongJingzhi
Created November 19, 2018 18:18
Show Gist options
  • Save XiongJingzhi/f8a7e4ffbf2cbc6f4834b406441d87d2 to your computer and use it in GitHub Desktop.
Save XiongJingzhi/f8a7e4ffbf2cbc6f4834b406441d87d2 to your computer and use it in GitHub Desktop.
reac实用代码
componentWillMount() {
const menuTreeNode = this.renderMenu(MenuConfig)
this.setState({
menuTreeNode
})
}
renderMenu = (config) => {
return config.map((item) => {
if (item.children) {
return (
<SubMenu title={item.title} key={item.key}>
{ this.renderMenu(item.children) }
</SubMenu>
)
}
return (
<Menu.Item title={item.title} key={item.key}>
<NavLink to={item.key}>{item.title}</NavLink>
</Menu.Item>
)
})
}
//使用时
{ this.state.menuTreeNode }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment