antd Tree组件中,自定义右键菜单
生活随笔
收集整理的這篇文章主要介紹了
antd Tree组件中,自定义右键菜单
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
最近項目中,有一個需求是自定義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"]}});};// 自定義右鍵菜單內(nèi)容getNodeTreeRightClickMenu = () => {const { pageX, pageY, id, categoryName } = { ...this.state.rightClickNodeTreeItem };const tmpStyle = {position: "absolute",left: `${pageX - 220}px`,top: `${pageY - 102}px`};const menu = (<div style={tmpStyle} className="self-right-menu"><a onClick={this.addDownGroup.bind(this, id)}>新增下級部門</a><a onClick={this.editGroup.bind(this, id, categoryName)}>修改</a><a>刪除目錄</a></div>);return this.state.rightClickNodeTreeItem == null ? "" : menu;};render(){return (...{this.getNodeTreeRightClickMenu()}...)}}export default Demo;轉(zhuǎn)載于:https://www.cnblogs.com/zhouyangla/p/9795998.html
總結(jié)
以上是生活随笔為你收集整理的antd Tree组件中,自定义右键菜单的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css继承和边框圆角 及 写三角形
- 下一篇: 译:Spring Boot 自动伸缩