0

I am looking to get the key of the menu item which was clicked in a list of contextmenu's, does anyone know how, this is how I create the context menu:

for(var i=0; i<10; i++) {
    appAPI.contextMenu.add("key_" + i, 'Test', function (data) {
        console.log('clicked with key: ', data);
    }, ["all"]);
}
John Doe
  • 836
  • 2
  • 10
  • 17

1 Answers1

0

Why do you need to get the key? ContextMenu listeners are declared per key, so you know which key it is. Using your code:

for(var i=0; i<10; i++) {
  (function(key) {
    appAPI.contextMenu.add(key, 'Test', function (data) {
      console.log('clicked with key: ',key, data);
    }, ["all"]);
  })("key_" + i);
}

[Disclosure] I am a Crossrider employee

Shlomo
  • 3,763
  • 11
  • 16