2011-06-10 42 views
4

如何使用Ext.tree.ViewDDPlugin的事件?如何在TreePanel上拖放後觸發事件

我有一個使用DDPplugin的TreePanel,但我想知道如何聆聽drop事件。

這是我的代碼如下所示:

var monPretree = Ext.create('Ext.tree.Panel',{ 
      id : 'treepanel', 
      title : 'TITRE', 
      //width : 800, 
      //height : 600, 
      width : 500, 
      enableDD: true, 
      useArrows : true, 
      viewConfig : { 
       plugins : { 
        ptype: 'treeviewdragdrop',  
         appendOnly: true,  
         listeners: {  
         drop: function (node, data, overModel, dropPosition) {   
           alert('CHANGE');  
         },  
         notifyDrop: function (dragSource, event, data) {   
           var nodeId = data.node.id;   
           alert(nodeId);  
         },  
         notifyOver: function (dragSource, event, data) {   
          alert('over'); 
         }  
        } 
       } 

      }, 
      singleExpand : false, 
      store : monPrestore, 
      rootVisible : false, 

我想解僱例如丟棄事件,但我的代碼不能正常工作

謝謝:)

回答

1

看看在DOC:一個新的子之前

beforeinsert(Tree tree, Node parent, Node node, Node refNode, Object options) 

火災插入一個節點在這棵樹,換貨政...假取消插入。 ...

+0

不被解僱。這是一個樹偵聽器還是一個ViewConfig偵聽器? – 2016-11-24 12:13:09

9

我有同樣的問題,並找到此頁。

有注意在文件中,事件部分: 「這一事件是通過TreeView的發射添加監聽到TreeView對象。」

我tryed以找到方法tree.Panel類來獲得視圖, 不成功。所以,你需要做的,只是把listners在配置部分viewConfig部(未在插件部分):

viewConfig : { 
       plugins : { 
        ptype: 'treeviewdragdrop',  
        ... 
       }, 
       listeners: {  
         drop: function (node, data, overModel, dropPosition) {   
           alert('CHANGE');  
         },   
        } 
       } 

      }, 

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.tree.plugin.TreeViewDragDrop-event-drop

+0

參數是否正確? 'node'不是樹節點。無法獲取移動的節點的父節點。 – 2016-11-24 12:08:32

-1

您還可以通過重寫dropConfig一個的TreeGrid或內趕上下降事件TreePanel中。這是我如何做的一個例子。

var myTree = new Tree.TreePanel({ 
    id: 'treepanel', 
    title: 'My Title', 
    enableDD: true, 
    ddGroup: 'GridDD', 
    dataUrl: 'yourMethodURLForJSONData', 
    dropConfig: { 
     dropAllowed: true, 
     ddGroup: "GridDD", 
     notifyDrop: function(source, e, data) { 
      alert("A node/leaf is dropped"); 

      //If you want few more details 
      if (data.grid) { 
       var node = data.selections[0].data; 
       alert("This is a node dropped from a Grid."); 
      } else { 
       var node = data["node"]; 
       alert("This is a node dropped from a Tree."); 
      } 

     } 
    } 
});​ 

您也可以對Ext.ux.tree.TreeGrid執行相同操作。希望它會有所幫助。

0

作爲除了安東的上述正確答案:下面的代碼演示瞭如何「從外面連接」從控制器等掉落事件,例如:

// Drag & Drop on the TreePanel 
    var ganttTreeView = ganttTreePanel.getView(); 
    ganttTreeView.on({ 
     'drop': me.onDrop, 
     'scope': this 
    });; 
相關問題