【问题标题】:crazy drag&drop in sencha extjssencha extjs 中的疯狂拖放
【发布时间】:2018-11-05 10:48:34
【问题描述】:

我是 sencha extjs 的初学者。

我对sencha extjs的拖拽有问题,我的代码是基于官方的拖拽示例但是并不能完全起作用,即只能通过左右拖拽文件来实现-向上,当我从上到下拖动时,它会发疯。

注意:官方示例通过从面板的任一侧拖动文件来工作。

视图代码

Ext.define('KitchenSink.view.drag.File', {
    extend: 'Ext.panel.Panel',
    xtype: 'drag.file',

    controller: 'drag.file',

    requires: [
        'Ext.layout.container.Fit'
    ],

    title: 'File Drag',
    draggable: true,
    width: 500,
    height: 300,
    bodyPadding: 5,
    layout: 'fit',

    bodyCls: 'drag-file-ct',

    html: '<div class="drag-file-label">' +
        'Drop some files here' +
        '</div>' +
        '<div class="drag-file-icon"></div>'
});

控制器视图的代码

Ext.define('KitchenSink.view.drag.FileViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.drag.file',

    requires: ['Ext.drag.Target'],

    afterRender: function(view) {
        var body = view.body;

        if (window.File && window.FileList && window.FileReader) {
            this.target = new Ext.drag.Target({
                element: body,
                listeners: {
                    scope: this,
                    dragenter: this.onDragEnter,
                    dragleave: this.onDragLeave,
                    drop: this.onDrop
                }
            });
        } else {
            body.down('.drag-file-label').setHtml(
                'File dragging is not supported by your browser'
            );
            body.el.addCls('nosupport');
        }
    },

    onDragEnter: function() {
        this.getView().body.addCls('active');
        //console.log("Enter");    
    },

    onDragLeave: function() {
        this.getView().body.removeCls('active');
        //console.log("Fuera");    
    },

    onDrop: function(target, info) {
        var view = this.getView(),
            body = view.body,
            icon = body.down('.drag-file-icon');

        body.removeCls('active').addCls('dropped');
        icon.addCls('fa-spin');

        var me = this,
            files = info.files,
            len = files.length,
            s;

        if (len > 1) {
            s = 'Dropped ' + len + ' files.';
        } else {
            s = 'Dropped ' + files[0].name;
        }

        Ext.toast({
            html: s,
            closable: false,
            align: 't',
            slideInDuration: 400,
            minWidth: 400
        });

        me.timer = Ext.defer(function() {
            if (!view.destroyed) {
                icon.removeCls('fa-spin');
                icon.fadeOut({
                    callback: function() {
                        body.removeCls('dropped');
                        icon.setOpacity(1);
                        icon.show();
                    }
                });
            }
            me.timer = null;
        }, 2000);
    },

    destroy: function() {
        Ext.undefer(this.timer);
        this.target = Ext.destroy(this.target);
        this.callParent();
    }
});

【问题讨论】:

  • 你的view代码和controller是一样的,能修一下吗?
  • 感谢您的回答。修好了!!

标签: extjs sencha-architect extjs6-classic


【解决方案1】:

我认为问题在于您错过了额外的 CSS 规则。例如,您必须禁止所有指针事件,否则在图标容器顶部拖动会导致触发“dragleave”事件。

以下是您需要的完整规则集和小提琴示例: 小提琴:https://fiddle.sencha.com/#view/editor&fiddle/2hac

.drag-file-ct .x-innerhtml {
  pointer-events: none;
}

.drag-file-fadeout {
  opacity: 0;
  -webkit-transition: all 1s ease-in-out;
  transition: all 1s ease-in-out;
}

.drag-file-label {
  font-size: 18px;
  padding-top: 30px;
  text-align: center;
  pointer-events: none;
}

.drag-file-icon {
  font-family: FontAwesome;
  display: block;
  font-size: 64px;
  margin-top: 50px;
  text-align: center;
  pointer-events: none;
}
.active .drag-file-icon {
  display: block;
}
.active .drag-file-icon:after {
  content: "\f058";
  color: #8BC34A;
}
.dropped .drag-file-icon {
  display: block;
}
.dropped .drag-file-icon:after {
  content: "\f013";
  color: #9E9E9E;
}
.nosupport .drag-file-icon {
  display: block;
}
.nosupport .drag-file-icon:after {
  content: "\f119";
  color: #9E9E9E;
}

【讨论】:

  • 感谢您的回答,我的问题更进一步,原来我有这个结构Window-> form-> container(拖放)。如何找到对面板的引用,以便在那里执行拖放操作? myfiddle
  • 你的小提琴没有任何应该工作的项目。它甚至没有在您最初的问题中描述的具有drag-file-iconbodyCls: 'drag-file-ct', 的主要html 结构。你能更新你的小提琴并验证它是否完整吗?
  • 已修复。但我说,它不起作用,因为我无法获得视图。有什么想法可以让它与这个视图结构一起工作吗?
  • 我已经更新了你的小提琴,使用reference 来查找面板,并更新了控制器代码以查找引用而不是指向窗口的this.getView()
  • 感谢@Guilherme Lopes。它炒锅。我正在尝试使用 this.lookupReference 但它不起作用。 this.lookup('reference') 和 this.lookupReference('reference') 有什么区别?
【解决方案2】:

FIDDLE

一开始我也遇到了这个问题,但后来我用元素 id asdasd 替换了目标元素 body 并且它起作用了。好像是关于图层的。

【讨论】:

    猜你喜欢
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    相关资源
    最近更新 更多