2017-01-18 57 views
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); 
    } 
} 
}); 

回答

0

愚蠢的错误,我忘了更新的的listItem上下文。