开发者

Detect target treenode when dragging items to the TreePanel instance

I have GridPanel and TreePanel instances. Elements from GridPanel could be dragged into the treepanel. But I can't detect which tree node receives these dragged items.

I initialize tree panel DD with the following code (method of class derived from Ext.tree.TreePanel):

initDD: function() {
    var treePanelDropTargetEl = this.getEl();
    var treePanelDropTarget = new Ext.dd.DropTarget(treePanelDropTargetEl, {
        ddGroup: 'ddgroup-1',
        notifyDrop: function(ddSource, e, data) {
            // do something with data, here I need to know target tree node
            return true;
        }
    });
}

So how can I find out which tree node received dragged items in the "开发者_Python百科notifyDrop" handler. I can take e.getTarget() and calculate the node but I don't like that method.


If you use a TreeDropZone (instead of DropTarget) you'll have more tree-specific options and events like onNodeDrop. Note that there are many ways to do DnD with Ext JS.


Here is some kind of solution

MyTreePanel = Ext.extend(Ext.tree.TreePanel, {
  listeners: {
    nodedragover: function(e) {
      // remember node
      this.targetDropNode = e.target;
    }
  }

  initComponent: function() {
    // other initialization steps
    this.targetDropNode = false;
    var config = {
      // ...
      dropConfig: {
        ddGroup: 'mygroupdd',
        notifyDrop: function(ddSource, e, data) {
          // process here using treepanel.targetDropNode
        }
      }
      }
      // ...
    };
    // other initialization steps
  }

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜