2

我试图弄清楚是否有一种方法可以配置 Ext JS 树面板拖放功能,以允许将树面板中的树节点转移到另一个配置有不可见根的树面板。两个树面板都配置为不显示根节点,因此树面板看起来有多个根节点。

我创建了一个jsFiddle 脚本,其中包含两个树面板的工作实现。将文件夹条目从树 1 拖放到树 2 是可行的,因为显示了树 2 的根节点,但是一旦我将树 2 的 rootVisible 属性设置为 false,就无法将文件夹节点从树 1 拖放到树 2 . 这是来自 jsFiddle 脚本的代码:

Ext.onReady(function () {
    Ext.define('Folder', {
        extend: 'Ext.data.Model',
        fields: [{
            name: 'id',
            type: 'int'
        }, {
            name: 'parentId',
            type: 'int'
        }, {
            name: 'name',
            type: 'string'
        }]
    });


    var store1 = Ext.create('Ext.data.TreeStore', {
        model: 'Folder',
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'folders'
            }
        }
    });


    var tree1 = Ext.create('Ext.tree.Panel', {
        itemId: 'tree1',
        store: store1,
        rootVisible: false,
        useArrows: true,
        flex: 1,
        title: 'Tree 1',
        root: [],
        columns: [{
            xtype: 'treecolumn',
            dataIndex: 'name',
            flex: 1
        }],
        viewConfig: {
            plugins: {
                ptype: 'treeviewdragdrop',
                appendOnly: true,
                dragGroup: 'firstTreeDDGroup',
                dropGroup: 'secondTreeDDGroup'
            }
        },
        listeners: {
            afterrender: function (tree) {
                var root = tree.getRootNode();


                // load static data
                root.appendChild([{
                    id: 1,
                    parentId: -1,
                    name: 'Folder 1',
                    expanded: true,
                    folders: [{
                        id: 11,
                        parentId: 1,
                        name: 'Folder 1.1',
                        folders: []
                    }, {
                        id: 12,
                        parentId: 1,
                        name: 'Folder 1.2',
                        folders: []
                    }]
                }, {
                    id: 2,
                    parentId: -1,
                    name: 'Folder 2',
                    folders: [{
                        id: 21,
                        parentId: 2,
                        name: 'Folder 2.1',
                        folders: []
                    }, {
                        id: 22,
                        parentId: 2,
                        name: 'Folder 2.2',
                        folders: []
                    }]
                }]);
            }
        }
    });


    var store2 = Ext.create('Ext.data.TreeStore', {
        model: 'Folder',
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'folders'
            }
        }
    });


    var tree2 = Ext.create('Ext.tree.Panel', {
        itemId: 'tree2',
        store: store2,
        rootVisible: true,
        useArrows: true,
        flex: 1,
        title: 'Tree 2',
        root: [],
        columns: [{
            xtype: 'treecolumn',
            dataIndex: 'name',
            flex: 1
        }],
        viewConfig: {
            plugins: {
                ptype: 'treeviewdragdrop',
                allowContainerDrop: true,
                allowParentInsert: true,
                appendOnly: true,
                dragGroup: 'secondTreeDDGroup',
                dropGroup: 'firstTreeDDGroup'
            }
        }
    });


    Ext.create('Ext.window.Window', {
        width: 550,
        height: 300,


        layout: {
            type: 'hbox',
            align: 'stretch'
        },


        items: [tree1, tree2]
    }).show();
});
4

0 回答 0