2014-05-03 52 views
0

我在ExtJs(Tree-1和Tree-2)中開發了兩個樹面板。在所有情況下,這些樹木正在拖拽兩個樹木之間。我只想在以下情況下拖放 (從樹-1到樹-2),(從樹-1到樹-1)和(從樹-2到樹-2)。這是要限制從樹-2到樹-1的拖放。以下是我的源代碼。限制在ExtJs樹面板中的拖放

/*Tree1*/ 
    Ext.create('Ext.tree.Panel', { 
       title: 'From Agent:', 
       collapsible: true, 
       collapseDirection: Ext.Component.DIRECTION_TOP, 
       frame:true, 
       width: 310, 
       minHeight: 50, 
       margin: '0 0 0 0', 
       store: store1, 
       listeners:{ 
        checkchange:function(node, checked, eOpts){ 
         node.cascadeBy(function(n){n.set('checked', checked);}); 
        } 
       }, 
       rootVisible: false, 
       viewConfig: { 
        plugins: { 
         ptype: 'treeviewdragdrop', 
         sortOnDrop: true, 
         containerScroll: true 
        } 
       }, 
       sorters: [{ 
        property: 'text', 
        direction: 'ASC' 
       }] 
      }), 

/*Tree2*/ 
      Ext.create('Ext.tree.Panel', { 
       title: 'To Agent:', 
       frame: true, 
       collapsible: true, 
       collapseDirection: Ext.Component.DIRECTION_TOP, 
       width: 310, 
       margin: '0 0 0 20', 
       minHeight: 50, 
       store: store2, 
       listeners:{ 
        checkchange:function(node, checked, eOpts){ 
         node.cascadeBy(function(n){n.set('checked', checked);}); 
        } 
       }, 
       rootVisible: false, 
       viewConfig: { 
        plugins: { 
         ptype: 'treeviewdragdrop', 
         sortOnDrop: true, 
         containerScroll: true 
        } 
       }, 
       sorters: [{ 
        property: 'text', 
        direction: 'ASC' 
       }] 
      }), 

這些代碼可以在拖放時進行剪切和粘貼。我想將這些代碼作爲複製和粘貼,同時拖放。請幫幫我。 在此先感謝。

+1

任何人都可以幫助我,請。我在等。 –

回答

2

看看這個例子中從文檔:

http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/tree/custom-drop-logic.html

基本上它使用nodedragover事件來控制,當一個可以丟棄或沒有。

當您不想允許放置時返回false。

至於使它複製,而不是切割時,文檔中提到以下(雖然我從來沒有嘗試過自己):

此插件提供阻力和/或一個TreeView拖放功能。

它創建DragZone的專用實例,它知道如何拖動 出一個TreeView和加載被傳遞到 具有以下性質的合作DragZone的方法將數據對象:

副本:布爾

TreeView的副本屬性的值,或真如果TreeView的是 與allowCopy配置:真當 拖拽操作開始按下控制鍵。

嘗試將設置copy: true設置爲兩個視圖。