如何在拖放后触发事件放在树面板上

发布于 2024-11-14 14:23:40 字数 1347 浏览 1 评论 0 原文

如何使用 Ext.tree.ViewDDPlugin 的事件?

我有一个使用 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,

例如,我想触发放置事件,但我的代码不起作用,

谢谢:)

How can I use Ext.tree.ViewDDPlugin's events?

I have a TreePanel that uses DDPplugin, but I'd like to know how to listen to the drop event.

This is what my code looks like:

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,

I would like to fire drop events for example, but my code doesn't work

Thanks :)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

真心难拥有 2024-11-21 14:23:40

我有同样的问题并找到了此页面。

文档中的事件部分有注释:
“此事件是通过 TreeView 触发的。向 TreeView 对象添加侦听器”

我尝试在 tree.Panel 类中找到方法来获取视图,但未成功。因此,您需要做的就是将侦听器块放在配置中的 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

I've got same question and found this page.

There is note in documentation, in event section:
"This event is fired through the TreeView. Add listeners to the TreeView object"

I've tryed to found method in tree.Panel class to get view, unsuccessfully. So, all you need to do, just put listners block in configuration to viewConfig section (not in plugin section):

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

缱绻入梦 2024-11-21 14:23:40

看一下文档:

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

在将新子文档插入此树中的节点之前触发,返回 false 以取消插入。 ...

Take a look at the doc :

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

Fires before a new child is inserted in a node in this tree, return false to cancel the insert. ...

り繁华旳梦境 2024-11-21 14:23:40

作为上面安东正确答案的补充:下面的代码显示了如何“从外部连接”以删除事件,例如从控制器等:

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

As an addition to Anton's correct answer above: The code below shows how to "connect from the outside" to drop events, for example from a Controller etc:

    // Drag & Drop on the TreePanel
    var ganttTreeView = ganttTreePanel.getView();
    ganttTreeView.on({
        'drop': me.onDrop,
        'scope': this
    });;
心意如水 2024-11-21 14:23:40

您还可以通过重写 TreeGrid 或 TreePanel 内的 dropConfig 来捕获 drop 事件。这是我的做法的一个例子。

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 执行相同的操作。希望它会有所帮助。

You can also catch the drop event by overriding dropConfig inside a TreeGrid or TreePanel. Here is an example how I did.

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.");
            }

        }
    }
});​

You can also do the same for Ext.ux.tree.TreeGrid. Hope It will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文