【发布时间】: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