Ext4.1 desktop 实现桌面图标可拖拽:
在 Desktop.js文件中的 initComponent 方法中 加入
me.shortcutsView.on('render', me.onRenderShortcut, me);
onRenderShortcut 方法如下
onRenderShortcut : function(v) {
var me = this;
me.shortcutsView.dragZone = new Ext.dd.DragZone(v.getEl(), {
getDragData: function(e) {
var sourceEl = e.getTarget(v.itemSelector, 10);
if (sourceEl) {
d = sourceEl.cloneNode(true);
d.id = Ext.id();
return {
ddel: d,
sourceEl: sourceEl,
sourceStore: v.store,
draggedRecord: v.getRecord(sourceEl)
}
}
},
getRepairXY: function() {
return this.dragData.repairXY;
},
onMouseUp : function(e){
var currDom = Ext.fly(this.dragData.sourceEl);
var oldXY = currDom.getXY();
var newXY = e.getXY();
var width = currDom.getWidth();
var height = currDom.getHeight();
if(Math.abs(oldXY[0]-newXY[0]) > width || Math.abs(oldXY[1]-newXY[1]) > height){
currDom.setXY(newXY);
Ext.get(this.dragData.sourceEl).frame('#8db2e3', 1);
}
}
});
}
ok 大功告成,现在桌面上的图标可以任意拖拽了.
效果图