简体   繁体   English

使用 Material UI 反应 TypeScript

[英]React TypeScript with Material UI

I would like to ask for help.我想寻求帮助。 How can I be able to render these menus under their correct and proper category menu?我怎样才能在它们正确和适当的类别菜单下呈现这些菜单? Currently, they would just pile against each other instead of rendering from their proper menu.目前,它们只是相互堆砌,而不是从其正确的菜单中进行渲染。 I am using React together with TypeScript and I have been working for this nonstop and haven't found an answer.我将 React 与 TypeScript 一起使用,我一直在为此不停地工作,但还没有找到答案。 Hope someone could help.希望有人能帮忙。

This is a sample photo of the problem.这是问题的示例照片。 They're all overlapping and rendering together instead of rendering it differently from the other menu.它们都重叠并一起渲染,而不是与其他菜单不同地渲染。

在此处输入图像描述

  • This Message Menu would only render a Menu List drop down menu.此消息菜单只会呈现菜单列表下拉菜单。

在此处输入图像描述

  • This Operation Menu would and should only render Ack, Unack, Clear, and Comment此操作菜单将并且应该只呈现 Ack、Unack、Clear 和 Comment

Here's my source code.这是我的源代码。

const handleClick = (index: null, event: React.MouseEvent<HTMLButtonElement>) => {
  setAnchorEl(event.currentTarget);
};

<Menu
  id="basic-menu"
  anchorEl={anchorEl}
  open={open}
  onClose={handleClose}
  MenuListProps={{
    "aria-labelledby": "basic-button",
  }}
>
  {customtoolinfo.menu_sub.map((custommenusubtool: any) => (
    <MenuItem onClick={handleClose}>
      {custommenusubtool.menu_sub_name}
    </MenuItem>
  ))}
</Menu>

The issue is because you have same anchorEl value of all sub menus.问题是因为所有子菜单的anchorEl值相同。 This issue can be fixed in many ways.可以通过多种方式解决此问题。 One way is to have only one menu and render it's sub-menus based on condition or second way is to have different anchorEl state for every submenu and control them based on menu一种方法是只有一个菜单并根据条件渲染它的子菜单,或者第二种方法是为每个子菜单设置不同的anchorEl状态并根据菜单控制它们

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

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