简体   繁体   English

React语义UI-可关闭菜单表格/选项卡

[英]React semantic-ui - Closable menu tabular / tab

<Menu tabular>
 {
  menus.map((menu, index) => (
   <Menu.Item 
    key={index} 
    name={menu.name} 
    active={this.props.location.pathname === menu.path} 
    onClick={() => {this.props.handleOpenClick(menu)}} 
   >
    {menu.name}
    <Button onClick={() =>  {this.props.handleCloseClick(index)}}>X</Button>
   </Menu.Item>
  ))
 }
</Menu>

I want to create a dynamic tabular layout with closable feature by using Menu and tabular option. 我想通过使用Menutabular选项创建具有可关闭功能的动态表格布局。 I put the Button component inside a Menu.Item and implement the onClick event. 我将Button组件放在Menu.Item并实现onClick事件。 When the buton is clicked, it's also calling handleOpenClick() function on the Menu.Item component. 单击按钮后,它还会在Menu.Item组件上调用handleOpenClick()函数。 I need to call the handleCloseClick() only. 我只需要调用handleCloseClick()

Is there any suggestion ? 有什么建议吗?

Sorry for my bad english 对不起,我的英语不好

Try adding e.stopPropagation() . 尝试添加e.stopPropagation()

<Menu tabular>
{
menus.map((menu, index) => (
    <Menu.Item 
        key={index} 
        name={menu.name} 
        active={this.props.location.pathname === menu.path} 
        onClick={() => {this.props.handleOpenClick(menu)}} 
    >
        {menu.name}
        <Button onClick={e =>  {
            e.stopPropagation();
            this.props.handleCloseClick(index);
        }}>X</Button>
    </Menu.Item>
    ))
}
</Menu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM