antd Tree组件中,自定义右键菜单

最近项目中,有一个需求是自定义antd的Tree组件的右键菜单功能。

直接上代码

class Demo extends Component {
  state = {
    rightClickNodeTreeItem: {
      pageX: "",
      pageY: "",
      id: "",
      categoryName: ""
    }
  }

  // tree列表上右键事件
  onRightClick = e => {
    this.setState({
      rightClickNodeTreeItem: {
        pageX: e.event.pageX,
        pageY: e.event.pageY,
        id: e.node.props["data-key"],
        categoryName: e.node.props["data-title"]
      }
    });
  };

  // 自定义右键菜单内容

   getNodeTreeRightClickMenu = () => {
    const { pageX, pageY, id, categoryName } = { ...this.state.rightClickNodeTreeItem };
    const tmpStyle = {
      position: "absolute",
      left: `${pageX - 220}px`,
      top: `${pageY - 102}px`
    };
    const menu = (
      
    );
    return this.state.rightClickNodeTreeItem == null ? "" : menu;
  };

  render(){
   return (
     ...
      {this.getNodeTreeRightClickMenu()}
     ...
   )
  }

}

export default Demo;

你可能感兴趣的:(antd Tree组件中,自定义右键菜单)