0
我有自定義ListItems多個列表(他們都有相同的),我想讓他們排序,並能夠拖動&將他們拖到另一個列表。拖放到自定義ListItem列表
所有這些工作正常,但是當我選擇一個Droped ListItem我得到一個異常,該項目不是這個小部件的子項。另外當我調用listItem列表上的indexOf方法我得到-1。
因此,當我在列表中調用getChildren時(插入前後),元素在列表中,並且視圖也正確地顯示它,即使是選擇!
下面是我列出的代碼:由我
qx.Class.define("padawan.quicksearch.SearchList", {
extend : qx.ui.form.List,
construct : function() {
this.base(arguments);
this.context = arguments[0];
this.setHeight(null);
this.setEnableInlineFind(false);
this.setDroppable(true);
this.setDraggable(true);
// create the controller
var controller = new qx.data.controller.List(null, this);
controller.setDelegate({
createItem : function() {
return new padawan.quicksearch.SucheComposite(this.context);
},
bindItem : function(controller, item, id) {
controller.bindProperty("", "model", null, item, id);
}
});
// Create drag indicator
var indicator = new qx.ui.core.Widget();
indicator.setDecorator(new qx.ui.decoration.Decorator().set({
widthTop : 1,
styleTop : "solid",
colorTop : "black"
}));
indicator.setHeight(0);
indicator.setOpacity(0.5);
indicator.setZIndex(100);
indicator.setLayoutProperties({
left : -1000,
top : -1000
});
indicator.setDroppable(true);
qx.core.Init.getApplication().getRoot().add(indicator);
// Just add a move action
this.addListener("dragstart", function(e) {
var item = this.getSucheComposite(e.getOriginalTarget());
if (!item) {
e.preventDefault();
return;
}
e.addType("items");
e.addAction("move");
});
this.addListener("droprequest", function(e) {
e.addData("items", [e.getDragTarget()]);
}, this);
this.addListener("dragend", function(e) {
// Move indicator away
indicator.setDomPosition(-1000, -1000);
});
this.addListener("drag", function(e) {
var orig = e.getOriginalTarget();
// if (!qx.ui.core.Widget.contains(this, orig) && orig != indicator)
// {
// return;
// }
var origCoords = orig.getContentLocation();
indicator.setWidth(orig.getBounds().width);
indicator.setDomPosition(origCoords.left, origCoords.top);
});
this.addListener("drop", function(e) {
var selection = e.getData("items")[0];
this.__reorderList(selection, e.getOriginalTarget(), e.getTarget());
}, this);
},
members : {
getSucheComposite : function(child) {
if (child.classname == "padawan.quicksearch.SucheComposite")
return child;
while (child) {
child = child.getLayoutParent();
if ("padawan.quicksearch.SucheComposite" == child.classname) {
return child;
}
}
return child;
},
__reorderList : function(selection, target, list) {
selection = this.getSucheComposite(selection);
if (target.classname !== "padawan.quicksearch.SucheComposite" || !selection) {
return;
}
switch(this.context.type){
case 'Zeile':
selection.setIsFilter(false);
selection.setIsRow(true);
selection.setIsColumn(false);
break;
case 'Filter':
selection.setIsFilter(true);
selection.setIsRow(false);
selection.setIsColumn(false);
break;
case 'Spalte':
selection.setIsFilter(false);
selection.setIsRow(false);
selection.setIsColumn(true);
break;
}
list.addBefore(selection, target);
}
}
});