DynaTree 在左键单击后右键单击时有两个突出显示的节点

发布于 2024-12-14 18:31:57 字数 602 浏览 3 评论 0原文

我的问题是,每当我左键单击一个动态树节点,然后右键单击另一个动态树节点以显示我的上下文菜单时,左键单击的节点仍以蓝色突出显示,因此我最终会得到两个蓝色节点。如果我右键单击连续的节点,突出显示将正常工作,但左键单击的节点仍保持突出显示。

左键单击处理会清除 mouseup 上的前一个节点。我启动上下文菜单处理,通过

document.oncontextmenu=contextMenu 

它也可以在鼠标松开时调用。

我尝试捕获右键 mouseup 事件并使上下文菜单节点处于活动状态,认为这会改变左键单击节点的状态,但事实并非如此。

$("#tree").mouseup(function(e){
   if(e.button == 2){
      e.target.setActive();// right mouse up
  }     
}); 

当右键单击另一个节点时,如何使最后一个左键单击的节点取消突出显示?同时突出显示两个节点看起来不太正确。我注意到,当右键单击另一个节点时,dynatree 上下文菜单演示不会取消突出显示先前左键单击的节点,这是设计使然吗?你能绕过它吗?

谢谢, 铝

My problem is whenever I left click a dynatree node then right click another dynatree node to display my context menu the node which was left clicked remains highlighted in blue so I end up with two nodes in blue. If I then right click successive nodes the highlighting works correctly but the left clicked node remains highlighted.

The left click processing clears the previous node on mouseup. I initiate context menu processing via

document.oncontextmenu=contextMenu 

which is also called on mouse up.

I have tried to capture the right button mouseup event and make the context menu node active thinking that would change the state of the left clickked node but not so.

$("#tree").mouseup(function(e){
   if(e.button == 2){
      e.target.setActive();// right mouse up
  }     
}); 

How should I get the last left clicked node to unhighlight when another node is right clicked ? It does not look right to have two nodes highlighted at once. I have noticed the dynatree context menu demo does not unhighlight the previously left clicked node when another node is right clicked so is this by design ?? Can you get around it ?

Thanks,
Al

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

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

发布评论

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

评论(4

一曲爱恨情仇 2024-12-21 18:32:16

我在显示器周围单击时发现的另一个更改

而不是

}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;  
}   

使用

}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;
    if(elem.tagName != 'A'){
        elem = e.target;
    }  
}  

这纠正了单击非 A 元素时重新出现旧突出显示问题的问题。

One more change I found while clicking around the display

Instead of

}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;  
}   

use

}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;
    if(elem.tagName != 'A'){
        elem = e.target;
    }  
}  

This corrects a issue where the old highlighting problem reappears of a non A element is clicked.

Al

jJeQQOZ5 2024-12-21 18:32:13

我知道这已经很旧了,但我刚刚遇到了同样的问题。当手动尝试管理节点上的 'dynatree-active' 类以强制突出显示时,我遇到了选择多个节点的问题。通过使用左键单击和右键单击,dynatree 管理所有选择和取消选择活动节点。

$("#tree").mouseup(function(e){
        if(e.button == 2) e.target.click();
}); 

我在这个问题上挣扎了一段时间,我希望它能为某人减轻一些痛苦。

I know this is old, but I just ran into the same problem. When manually trying to manage 'dynatree-active' classes on nodes to force highlighting, I was having issues with multiple nodes being selected. By using a left click along with the right click, dynatree managed all of the selecting and deselecting active nodes.

$("#tree").mouseup(function(e){
        if(e.button == 2) e.target.click();
}); 

I struggled with this one for a bit, I hope it can save someone some pain.

你与昨日 2024-12-21 18:32:11

我需要添加一个添加到 jquery.dynatree.js 的简短方法才能使其工作。

//--- Class members ------------------------------------------------------------

DynaTree.prototype = {
// Constructor
// member functions


getDtNodeFromElement2: function(elem) {
    var sourceNode = getDtNodeFromElement(elem);
    return sourceNode;
},

I need to add a short method I added to jquery.dynatree.js to make it work.

//--- Class members ------------------------------------------------------------

DynaTree.prototype = {
// Constructor
// member functions


getDtNodeFromElement2: function(elem) {
    var sourceNode = getDtNodeFromElement(elem);
    return sourceNode;
},
终止放荡 2024-12-21 18:32:05

好的,这可以

在我创建动态树后在 myfile.js 中添加:

var dtnode;   //dynatree node Global <--ADDED
var elem;     //DOM node Global  <--ADDED


Function BuildTree()


//ADDED following code after the dynatree was loaded 

$("#tree").mouseup(function(e){
if(e.button == 2){ //RIGHT MOUSE UP 
    if(!(elem == null)){
        var elem2 = e.currentTarget.document.activeElement;
        dtnode = tree.getDtNodeFromElement2(elem);
        dtnode.deactivate();
        elem = null;
        }   
}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;  
}   
}); 

//In jquery.dynatree.js
//$Version: 1.1.1$
//$Revision: 481, 2011-03-02 07:25:35$

//The following changes were made:

getSelectedNodes: function() {
    return this.tree.getSelectedNodes();
},

// AFTER THE ABOVE FUNCTION THE FOLLOWING FUNCTION WAS ADDED

getDtNodeFromElement2: function() {
    return this.tree.getDtNodeFromElement2();
},

//********************************************************

getSelectedNodes: function(stopOnParents) {
    var nodeList = [];
    this.tnRoot.visit(function(node){
    if( node.bSelected ) {
        nodeList.push(node);
        if( stopOnParents === true ){
           return "skip"; // stop processing this branch
        }
    }
});
return nodeList;
},

// AFTER THE ABOVE FUNCTION THE FOLLOWING FUNCTION WAS ADDED 

getDtNodeFromElement2: function(elem) {
    var sourceNode = getDtNodeFromElement(elem);
    return sourceNode;
},

摘要:
通过跟踪要左键单击的最后一个元素并通过 getDtNodeFromElement2 公开 dynatree getDtNodeFromElement 方法,每当第一次右键单击节点时,就可以调用最后一个左键单击的节点上的 deactivate 方法。这消除了树节点的同时突出显示。

OK this works

In my myfile.js after I create the dynatree I added:

var dtnode;   //dynatree node Global <--ADDED
var elem;     //DOM node Global  <--ADDED


Function BuildTree()


//ADDED following code after the dynatree was loaded 

$("#tree").mouseup(function(e){
if(e.button == 2){ //RIGHT MOUSE UP 
    if(!(elem == null)){
        var elem2 = e.currentTarget.document.activeElement;
        dtnode = tree.getDtNodeFromElement2(elem);
        dtnode.deactivate();
        elem = null;
        }   
}else{//LEFT MOUSE UP
    if(!(elem == null)){
        elem = null;
    }
    elem = e.currentTarget.document.activeElement;  
}   
}); 

//In jquery.dynatree.js
//$Version: 1.1.1$
//$Revision: 481, 2011-03-02 07:25:35$

//The following changes were made:

getSelectedNodes: function() {
    return this.tree.getSelectedNodes();
},

// AFTER THE ABOVE FUNCTION THE FOLLOWING FUNCTION WAS ADDED

getDtNodeFromElement2: function() {
    return this.tree.getDtNodeFromElement2();
},

//********************************************************

getSelectedNodes: function(stopOnParents) {
    var nodeList = [];
    this.tnRoot.visit(function(node){
    if( node.bSelected ) {
        nodeList.push(node);
        if( stopOnParents === true ){
           return "skip"; // stop processing this branch
        }
    }
});
return nodeList;
},

// AFTER THE ABOVE FUNCTION THE FOLLOWING FUNCTION WAS ADDED 

getDtNodeFromElement2: function(elem) {
    var sourceNode = getDtNodeFromElement(elem);
    return sourceNode;
},

Summary:
By keeping track of the last element to be left clicked and exposing the dynatree getDtNodeFromElement method through getDtNodeFromElement2 it is possible to call the deactivate method on the last left clicked node whenever the first right click of a node occurs. This eliminates simultaneous highlighting of tree nodes.

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