Vue Menu - Access the Clicked Item
To access the clicked item, handle the itemClick event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the onItemClick property when you configure the UI component.
jQuery
$(function() { $("#menuContainer").dxMenu({ // ... onItemClick: function(e) { var itemData = e.itemData; var itemElement = e.itemElement; var itemIndex = e.itemIndex; // ... } }); });
Angular
<dx-menu ... (onItemClick)="itemClick($event)"> </dx-menu>
import { DxMenuModule } from "devextreme-angular"; // ... export class AppComponent { itemClick(e) { const { itemData, itemElement, itemIndex } = e; // ... } } @NgModule({ imports: [ // ... DxMenuModule ], // ... })
Vue
<template> <DxMenu ... @item-click="itemClick" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxMenu from 'devextreme-vue/menu'; export default { components: { DxMenu }, methods: { itemClick(e) { const { itemData, itemElement, itemIndex } = e; // ... } } }; </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Menu } from 'devextreme-react/menu'; class App extends React.Component { render() { return ( <Menu ... onItemClick={this.itemClick} /> ); } itemClick = (e) => { const { itemData, itemElement, itemIndex } = e; // ... } } export default App;
jQuery
If you are going to change event handlers at runtime, or if you need to attach several handlers to the itemClick event, subscribe to this event using the on(eventName, eventHandler) method.
var itemClickHandler1 = function(e) { // First handler of the "itemClick" event }; var itemClickHandler2 = function(e) { // Second handler of the "itemClick" event }; $("#menuContainer").dxMenu("instance") .on("itemClick", itemClickHandler1) .on("itemClick", itemClickHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.