How to change name in context menu dynamicaly by a condition

F4k3d

I am using this contextmenu plugin for jQuery:

http://swisnl.github.io/jQuery-contextMenu/demo/trigger-left-click.html.

and I am trying to change the name of a menu item dynamically by a simple condition. Unfortunately it isn't possible to change a menu item's name dynamically or I don't know how to do so...

I tried it this way:

   items: {
           "item": {name: (x > 10) ? 'name1' : 'name2', disabled: false},
           "sep1": "----------------",
           ....
   }

but it isn't working. Then I tried it with an anonymous function:

 items: {
         "item": {name: function(){ return (x > 10) ? 'name1' : 'name2'; }, disabled: false},
         "sep1": "----------------",
         ....
 }

but it isn't working as well... Now I have no other clue, so I am asking you for help. Do you have useful advice for me? Any help is appreciated.

Thanks in advance.

rafaelcastrocouto

The name will be defined at the beginning, not every click. If you wanna redefine the item name every time you should do it like this:

var x = 0;
$(function() {
  $.contextMenu({
    selector: '.context-menu-one', 
    callback: function(key, options) {
      var m = "clicked: " + key;
    },
    items: {
      "edit": {name: "Edit", icon: "edit"},
      "cut": {name: "Cut", icon: "cut"},
      copy: {name: "Copy", icon: "copy"},
      "paste": {name: "Paste", icon: "paste"},
      "delete": {name: "Delete", icon: "delete"},
      "sep1": "---------",
      "quit": {name: "Quit", icon: function(){
        return 'icon icon-quit';
      }}
    }
  });

  $('.context-menu-one').on('contextmenu', function(e){
    $('.icon-edit span').text('x: ' + x);
    x++;
  });    
});
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="http://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.min.js"></script>
  <link rel="stylesheet" href="http://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.min.css">
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<span class="context-menu-one btn btn-neutral">right click me</span>
</body>
</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change name in context menu dynamicaly by a condition

From Dev

Binding property to dynamicaly created item of context menu

From Dev

How to hide the menu item of context menu in wpf xaml based on condition

From Dev

How to hide the menu item of context menu in wpf xaml based on condition

From Dev

How to change a context menu items color

From Dev

How does the MDN website change the context menu?

From Dev

How to change the handsontable context menu language

From Dev

How to Change context menu of windows Explorer

From Dev

How to change the text color of context menu item

From Dev

Dynamicaly change class name of same class by adding number

From Dev

How to enable and disable dynamic context menu based on condition in DataGrid?

From Dev

Change android theme dynamicaly

From Dev

QML,How to dynamicaly change Item of Repeater from C++

From Dev

How can I change dynamicaly the opacity of a linegraph in D3?

From Dev

QML,How to dynamicaly change Item of Repeater from C++

From Dev

How to change Textmate's context menu key binding?

From Dev

How to change the keyboard shortcut for Firefox's context menu?

From Dev

Windows 7: How to change context menu item icon?

From Dev

How do I change the colour of context menu in Windows 10?

From Dev

Change menu name openerp

From Dev

How to create a class dynamicaly

From Dev

change text format of an span dynamicaly

From Dev

Chrome Extension: How to create context menu with custom name, instead of plugin name

From Dev

How to safely change OS name in grub boot menu?

From Dev

Get current control name from context menu

From Dev

Richtextbox context menu focus cursor wont change

From Dev

Change Properties accelerator in windows 8 context menu

From Java

How to create context menu for RecyclerView

From Dev

How to add a context menu to a `gframe`?

Related Related

  1. 1

    How to change name in context menu dynamicaly by a condition

  2. 2

    Binding property to dynamicaly created item of context menu

  3. 3

    How to hide the menu item of context menu in wpf xaml based on condition

  4. 4

    How to hide the menu item of context menu in wpf xaml based on condition

  5. 5

    How to change a context menu items color

  6. 6

    How does the MDN website change the context menu?

  7. 7

    How to change the handsontable context menu language

  8. 8

    How to Change context menu of windows Explorer

  9. 9

    How to change the text color of context menu item

  10. 10

    Dynamicaly change class name of same class by adding number

  11. 11

    How to enable and disable dynamic context menu based on condition in DataGrid?

  12. 12

    Change android theme dynamicaly

  13. 13

    QML,How to dynamicaly change Item of Repeater from C++

  14. 14

    How can I change dynamicaly the opacity of a linegraph in D3?

  15. 15

    QML,How to dynamicaly change Item of Repeater from C++

  16. 16

    How to change Textmate's context menu key binding?

  17. 17

    How to change the keyboard shortcut for Firefox's context menu?

  18. 18

    Windows 7: How to change context menu item icon?

  19. 19

    How do I change the colour of context menu in Windows 10?

  20. 20

    Change menu name openerp

  21. 21

    How to create a class dynamicaly

  22. 22

    change text format of an span dynamicaly

  23. 23

    Chrome Extension: How to create context menu with custom name, instead of plugin name

  24. 24

    How to safely change OS name in grub boot menu?

  25. 25

    Get current control name from context menu

  26. 26

    Richtextbox context menu focus cursor wont change

  27. 27

    Change Properties accelerator in windows 8 context menu

  28. 28

    How to create context menu for RecyclerView

  29. 29

    How to add a context menu to a `gframe`?

HotTag

Archive