Sencha Ext JS 4,可拖动面板“跳转”启动拖动事件时脱离父级

发布于 2024-12-28 17:37:09 字数 2747 浏览 4 评论 0原文

我有一个 ext js 4 应用程序,由父面板和子面板组成。父面板配置为拖放区,子面板可拖动。当我拖动子面板时,它会跳出屏幕。

这是我用来演示该行为的 YouTube 视频: http://youtu.be/ve6762fXUBo

这是我的源代码:

注意:在 onNodeDrop 我强制面板返回到 50x50 的位置,否则我将无法重复该行为。

Ext.define('CS.view.ViewDashboard', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.dashboard',
    layout: 'fit',
    items: [{
        xtype: 'panel',
        id: 'test_panel',
        title: 'test panel',
        html: 'test panel',
        draggable: true,
        constrain: true,
        border: true,
        width: 300,
        height: 300,
        listeners: {
            render: function(el){
                el.center();
            }
        }
    }],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'bottom',
        layout: 'hbox',
        pack: 'center',
        items: [{   
                xtype: 'splitbutton', 
                text: 'Applications',
                handler: function(){
                    console.log('splitbutton');
                },
                menu: new Ext.menu.Menu({
                    items: [
                        {text: 'Item 1', hander: function(){}},
                        {text: 'Item 2', hander: function(){}},
                    ]
                })
        }]
    }],
    listeners: {
        render: function(sender){

            console.log(sender);

            sender.dropZone = new Ext.dd.DropZone(sender.body, {

                getTargetFromEvent: function(e) {

                    console.log('getTargetFromEvent');

                    var temp = { 
                        x: e.getX() - this.DDMInstance.deltaX, 
                        y: e.getY() - this.DDMInstance.deltaY
                    };

                    console.log(temp);
                    return temp;

                },

                // On entry into a target node, highlight that node.
                onNodeEnter : function(target, dd, e, data){ 
                //    Ext.fly(target).addCls('my-row-highlight-class');
                },

                // On exit from a target node, unhighlight that node.
                onNodeOut : function(target, dd, e, data){ 
                //    Ext.fly(target).removeCls('my-row-highlight-class');
                },

                onNodeOver : function(target, dd, e, data){ 
                    return Ext.dd.DropZone.prototype.dropAllowed;
                },

                onNodeDrop : function(target, dd, e, data){

                    console.log('onNodeDrop');
                    data.panel.setPosition(50, 50, true);
                    return true;

                }
            });



        }
    }
});

I have an ext js 4 application that consists of a parent panel and a child panel. The parent panel is configured to be a dropzone, and the child is draggable. When I drag the child panel, it jumps off the screen.

Here is a youtube video I took to demonstrate the behavior:
http://youtu.be/ve6762fXUBo

And here is my source code:

NOTE: In onNodeDrop I force the panel back to position 50x50 otherwise I wouldn't be able to repeat the behavior.

Ext.define('CS.view.ViewDashboard', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.dashboard',
    layout: 'fit',
    items: [{
        xtype: 'panel',
        id: 'test_panel',
        title: 'test panel',
        html: 'test panel',
        draggable: true,
        constrain: true,
        border: true,
        width: 300,
        height: 300,
        listeners: {
            render: function(el){
                el.center();
            }
        }
    }],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'bottom',
        layout: 'hbox',
        pack: 'center',
        items: [{   
                xtype: 'splitbutton', 
                text: 'Applications',
                handler: function(){
                    console.log('splitbutton');
                },
                menu: new Ext.menu.Menu({
                    items: [
                        {text: 'Item 1', hander: function(){}},
                        {text: 'Item 2', hander: function(){}},
                    ]
                })
        }]
    }],
    listeners: {
        render: function(sender){

            console.log(sender);

            sender.dropZone = new Ext.dd.DropZone(sender.body, {

                getTargetFromEvent: function(e) {

                    console.log('getTargetFromEvent');

                    var temp = { 
                        x: e.getX() - this.DDMInstance.deltaX, 
                        y: e.getY() - this.DDMInstance.deltaY
                    };

                    console.log(temp);
                    return temp;

                },

                // On entry into a target node, highlight that node.
                onNodeEnter : function(target, dd, e, data){ 
                //    Ext.fly(target).addCls('my-row-highlight-class');
                },

                // On exit from a target node, unhighlight that node.
                onNodeOut : function(target, dd, e, data){ 
                //    Ext.fly(target).removeCls('my-row-highlight-class');
                },

                onNodeOver : function(target, dd, e, data){ 
                    return Ext.dd.DropZone.prototype.dropAllowed;
                },

                onNodeDrop : function(target, dd, e, data){

                    console.log('onNodeDrop');
                    data.panel.setPosition(50, 50, true);
                    return true;

                }
            });



        }
    }
});

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

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

发布评论

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