sydcanem / bootstrap-contextmenu

Context menu plugin for Twitter's Bootstrap framework
http://sydcanem.com/bootstrap-contextmenu/
645 stars 193 forks source link

onItem will be called twice when triggers a submenu item #83

Open XiaoMouR opened 9 years ago

XiaoMouR commented 9 years ago

I create a menu which has a submenu with two items.When I trigger one of items in submenus,the onItem in the option of contextmenu will be called twice. Follow is my code.

<!-- menu -->
<div id="context-menu">
      <ul class="dropdown-menu multi-level" role="menu">
        <li class="dropdown-submenu">
          <a href="javascript:;">item</a>
          <ul class="dropdown-menu">
            <li><a href="javascript:;">subitem1</a></li>
            <li><a href="javascript:;">subitem2</a></li>
          </ul>
        </li>
    </ul>
</div>
//option
  var ipsession_contextmenu = {
    target:"#context-menu",
    before: function(e,context){
    },
    onItem: function(context,e){
           alert($(e.target).text());
    }
  };

By the way,if I add "this.closemenu()" to the end of onItem,it will stop the second time calls.

oddui commented 9 years ago

I put e.stopPropagation() in onItem. It stops onItem being called multiple times. Not sure whether it breaks anything.

gjohncock commented 8 years ago

ive been playing around with this and cannot get it to termininate gracefully. if I just use the closemenu command it throws an error saying "e" is not valid. The reason it is happening on sub items is that its propogating up the menu tree and fires for all the parent li tags.
would be good if there was a way to tag an item as a parent as usually you dont want anything to happen when you click this item, its sole purpose is to display the submenu where all the active items are.