禁用/启用 jQuery Dynatree 的上下文菜单不起作用

发布于 2025-01-07 12:21:53 字数 733 浏览 1 评论 0原文

我正在使用 jQuery dynatree 以及此处<的上下文菜单< /a>.我遇到的问题是我无法启用/禁用上下文菜单或菜单中的单个项目。该插件说我应该能够做到这一点:

$("#contextMenu").enableContextMenu();

但这对我不起作用。这是菜单:

 <!-- Definition of context menu -->
 <div id="contextMenu">
     <ul id="myMenu" class="contextMenu">
       <li class="resubmit"><a href="#resubmit">Resend</a></li>
     </ul>
 </div>

如果我不进行任何启用/禁用操作,菜单会显示并正常工作,但在某些情况下菜单项不可用,因此我需要能够控制其状态。如果我输入启用/禁用,则根本不会显示菜单。

谁能分享一下他们是如何让它发挥作用的?

更新:如果删除上面的 DIV,我只能显示菜单。然后它会显示,但使用“myMenu”启用/禁用没有任何作用......

I am using the jQuery dynatree along with the context menu found here. The issue I'm having is that I can't get the enable/disable of the context menu or individual items in the menu to work. The plugin says I should be able to do this:

$("#contextMenu").enableContextMenu();

but that doesn't work for me. Here's the menu:

 <!-- Definition of context menu -->
 <div id="contextMenu">
     <ul id="myMenu" class="contextMenu">
       <li class="resubmit"><a href="#resubmit">Resend</a></li>
     </ul>
 </div>

The menu shows and works fine if I don't put any enable/disable, but there are cases where the menu item is not available so I need to be able to control its state. If I put in the enable/disable, the manu doesn't show at all.

Can anyone share how they got this to work?

UPDATE: I can only get the menu to show if I remove the DIV above. Then it will show, but enable/disable using "myMenu" does nothing...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小姐丶请自重 2025-01-14 12:21:53

遇到同样的问题,您实际上可以禁用上下文菜单触发器,例如:

$(".dynatree-title").contextMenu(false)

并使用 True 重新启用它。 dynatree-title 是触发器绑定到的元素。

希望这可以帮助其他偶然发现此问题的人。

上下文菜单文档

Came across the same issue, you can actually disable the context menu trigger like:

$(".dynatree-title").contextMenu(false)

And re-enable it with True. dynatree-title being the element the trigger is bound to.

Hope this helps anyone else who stumbles across this.

Context menu documentation

回忆凄美了谁 2025-01-14 12:21:53

我无法禁用菜单本身,因此我必须在选择项目后处理它:

switch( action ) 
{
    case "resubmit":
        //-- show verify dialog
      var selectedNode = $("#tree").dynatree("getActiveNode");
      if(selectedNode == null) 
           break;
      var parentTitle = selectedNode.parent.data.title;
      if( parentTitle == "Error" || parentTitle == "To Lab" || parentTitle == "From Lab" )
            $('#dialog-confirm').dialog('open');
             break;
    default:
             alert("Invalid action '" + action + "' to node " + node);
}

我只需检查是否选择了正确的类型节点才能执行操作(查看父级,即包含的文件夹)。

I couldn't disable the menu itself, so I had to handle it after the item is selected:

switch( action ) 
{
    case "resubmit":
        //-- show verify dialog
      var selectedNode = $("#tree").dynatree("getActiveNode");
      if(selectedNode == null) 
           break;
      var parentTitle = selectedNode.parent.data.title;
      if( parentTitle == "Error" || parentTitle == "To Lab" || parentTitle == "From Lab" )
            $('#dialog-confirm').dialog('open');
             break;
    default:
             alert("Invalid action '" + action + "' to node " + node);
}

I just check that the proper type node is selected to be able to take the action (look at parent, which is the containing folder).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文