【问题标题】:How to make swapable component in exJs or in javascript如何在 extJs 或 javascript 中制作可交换组件
【发布时间】:2021-11-17 09:26:17
【问题描述】:

如何在 exJs 或 javascript 中制作可交换组件。

我有两个组件,两者都是可拖动的。

            xtype : "panel",
            title: 'My Apps',
            region: 'east',
            width: 290,
            items:[{
                xtype : 'panel',
                cls: 'myCLS',
                iconCls : 'app-info-appstore',
                title: 'Home',
                draggable : true,
                html : 'Home.',
                listeners: {
                    'render': function(panel) {
                        panel.body.on('click', function() {
                            alert('onclick');
                        });
                     }
                 }
                
            },{
                xtype : 'panel',
                cls: 'myCLS',
                title: 'Profile',
                iconCls : "app-info-iconToure",
                draggable : true,
                html : 'Apps',
            }

当我将一个拖到另一个时,它是重叠的。我们如何在 extJS 中交换两个元素的位置。

任何其他库帮助也可以使用。

【问题讨论】:

    标签: javascript html extjs extjs6


    【解决方案1】:

    onDrop 你通过insert将它添加到父容器中。

    要获得正确的位置,您可以根据鼠标位置计算它或...

    onDrop 得到你当前所在的目标 dom 元素。

    const extComponent = Ext.ComponentManager.from(domEl),
          currentIndex = ... // search for the position of that item in parent
    
    parent.insert(droppedItem, currentIndex);
    

    进一步的工作

    • 如果您使用占位符代理,您甚至可以预览这些内容。
    • 如果您的组件大小相同,请使用 snap。

    示例

    Fiddle

    【讨论】:

    • @Dinkheler 我奖励了你。
    • @Dinkheler 谢谢你的小提琴。让我检查一下小提琴并实现它。
    • @Dinkheler +1 你的小提琴工作正常,但它不是consitent。虽然我正在努力进行更改并在我取得一些成功后进行更新。
    猜你喜欢
    • 2011-07-18
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    • 2018-11-05
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    相关资源
    最近更新 更多