ExtJs 4 - 从树拖到“空”树

发布于 2025-01-07 03:49:59 字数 2426 浏览 3 评论 0原文

从一棵树拖到另一棵树时,ExtJS 遇到问题。

我有一棵树,sourceTree,其中包含可从中拖动的所有元素。

我有另一棵树,targetTree,它有望包含从源树中拖动(选择)的所有元素。

var sourceStore = Ext.create('Ext.data.TreeStore', {
    model: 'MyTreeModel',
    proxy: {
        type: 'ajax',
        url: '/some_action_that_returns_tree_json',
        extraParams: { /*extra params*/
        },
        reader: {
            type: 'json',
            root: function (o) {
                if (o.children == null) {
                    return o.children;
                } else {
                    return o;
                }
            }
        }
    },
    folderSort: true
});

源树定义为:

{
    xtype: 'treepanel',
    flex: 5,
    iconCls: 'myiconcls',
    border: true,
    store: formstore,
    loadMask: true,
    rootVisible: false,
    title: 'Source',
    bodyStyle: 'font-style:bold',
    viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop',
            appendOnly: true
        }
    }
}

所以我有一个可以从中拖动的源树。

目标树定义为:

{
     xtype: 'treepanel',
     flex: 5, iconCls: 'mytreecls',
     border: true, 
     store: emptystore,
     rootVisible: false,
     title: 'Selected', 
     bodyStyle: 'font-style:bold',
     viewConfig: {
        emptyText: '',
        plugins: {
           ptype: 'treeviewdragdrop',
           allowContainerDrop: true,
           appendOnly: true
        },
        listeners: {
            drop: function (node, data, model, dropPosition, opts) {
                console.log(node);
            }
        }
    } 
}

我遇到的第一个问题是如何定义一个具有单个根节点的空树存储,如果未加载节点的数据,该根节点将调用代理 url。

源树将动态加载叶节点,如果我将它们拖动并添加到目标树,我想保留该功能。

我已经尝试了很多方法来设置默认根节点 - 但没有一个能够工作。

var emptystore= Ext.create('Ext.data.TreeStore', {
    model: 'TreeModel',
    proxy: {
        type: 'ajax',
        url: '/some_action_that_returns_tree_json',
        extraParams: { ... },
        reader: {
            type: 'json',
            root: { text:"My Root",...} // doesn't work, presumably becuase the ajax call overwrite it?
            }
        }
    }
});

最终结果应该是一个源树,我可以将其拖到另一棵树中。我不想删除我认为由 treeviewdragdropappendOnly 属性控制的拖动节点。我试图通过将 allowContainerDrop 设置为 true 来处理面板/容器上的掉落。

老实说,这是我第一次尝试 ExtJS D&D,所以感谢任何帮助。我显然已经阅读了教程,但找不到我的树对树 D&D。

预先感谢,

山姆

Having a problem with ExtJS when it comes to dragging from a tree to another tree.

I have one tree, sourceTree, that has all the elements available to drag from.

I have another tree, targetTree that will hopefully contain all the elements dragged (selected) from the source tree.

var sourceStore = Ext.create('Ext.data.TreeStore', {
    model: 'MyTreeModel',
    proxy: {
        type: 'ajax',
        url: '/some_action_that_returns_tree_json',
        extraParams: { /*extra params*/
        },
        reader: {
            type: 'json',
            root: function (o) {
                if (o.children == null) {
                    return o.children;
                } else {
                    return o;
                }
            }
        }
    },
    folderSort: true
});

the source tree is defined as:

{
    xtype: 'treepanel',
    flex: 5,
    iconCls: 'myiconcls',
    border: true,
    store: formstore,
    loadMask: true,
    rootVisible: false,
    title: 'Source',
    bodyStyle: 'font-style:bold',
    viewConfig: {
        plugins: {
            ptype: 'treeviewdragdrop',
            appendOnly: true
        }
    }
}

So I have a source tree I can drag from.

The target tree is defined as:

{
     xtype: 'treepanel',
     flex: 5, iconCls: 'mytreecls',
     border: true, 
     store: emptystore,
     rootVisible: false,
     title: 'Selected', 
     bodyStyle: 'font-style:bold',
     viewConfig: {
        emptyText: '',
        plugins: {
           ptype: 'treeviewdragdrop',
           allowContainerDrop: true,
           appendOnly: true
        },
        listeners: {
            drop: function (node, data, model, dropPosition, opts) {
                console.log(node);
            }
        }
    } 
}

The first problem I have is how can I define an empty treestore with a single root node that will call the proxy url if the data for the node is not loaded.

The source tree will load leaf nodes dynamically, if I drag and add them to the target tree I want to keep that functionality.

I've tried lots of ways to set default root node - none of which I've been able to get working.

var emptystore= Ext.create('Ext.data.TreeStore', {
    model: 'TreeModel',
    proxy: {
        type: 'ajax',
        url: '/some_action_that_returns_tree_json',
        extraParams: { ... },
        reader: {
            type: 'json',
            root: { text:"My Root",...} // doesn't work, presumably becuase the ajax call overwrite it?
            }
        }
    }
});

The end result should be a source tree that I can drag from into another tree. I don't want to remove the dragged node which I think is controlled by appendOnly property of treeviewdragdrop. I was trying to make it so I could handle the drop on the panel/container by setting allowContainerDrop to true.

To be honest this is my first endeavour into ExtJS D&D so any help appreciated. I've obviously read the tutorial but cannot find my on tree to tree D&D.

Thanks in advance,

Sam

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文