简体   繁体   中英

Flex tree control drag drop .item position

just facing a difficulty with tree control drag drop..
Suppose i have tree with drag-drop enabled. I want to which node(id) is droped inside which node.

1]if i drag "Cat1" node inside "Cat3",i want to identify ids of siblings of "cat1",and "cat3".

2]in general i want to know the ids of current element being moved along with
its new parent and new position and save these postions.

3] Also "cat4" when moved outside "cat3",i want know its position and its siblings id.

<mx:XML id="treeDP">
        <node label="Categories">
          <node label="Cat1" id="1" isBranch="true"/>            
          <node label="Cat2" id="2" isBranch="true"/>

           <node label="Cat3" id="3" isBranch="true">
             <node label="Cat4" id="4" isBranch="true"/>
         </node>          
        </node>
</mx:XML>

    <mx:Tree id="compBalanced" 
        width="420" height="439" 
        dataProvider="{treeDP}" 
        showRoot="false"
        labelField="@label"
        doubleClickEnabled="true"
        dragEnabled="true" 
        dropEnabled="true" 
        dragDrop="onDragDrop(event)"            
            />

I've meet a problem like this, when I had to check the node wich receive the children. To get the node parent, I'd used this :

public function getObjectTarget() : Object {
   var dropData : Object = tree.mx_internal::_dropData as Object;
   if (dropData.parent != null) {
      return dropData.parent;
   } else {
          // if there is not parent (root of the tree), I take the root directly
      var renderer : IListItemRenderer = tree.indexToItemRenderer(0);
      return renderer.data;
   }

hope this will help some one

temporarily solved the problem by listening to dragComplete on the tree
dragComplete="handleDragComplete(event)

When the drag is complete i get the changed dataprovider from the tree and then i recursively search the "dragged item"("id" + "label") in the changed dataprovider to find its position in the tree ie. "id" of the node in which the selected node is dropped(parent node). and fire the save to database api.

anyone has better options. pls reply

thanks :)

The DragEvent contains a dragSource element. It contains the element(s) being dragged. In case of a tree, it is of type "treeItems". var items:Array = event.dragSource.datForFormat("treeItems") as Array; When dragging a tree node, there is only one element, items[0] which can be easily located inside the (altered) tree.

There seems to be, however, no way to reveal where this item would be inserted if it were released at the current drag position (eg to prevent a node being dragged to a certain place). The 'calculateDropIndex()' function only calculates the row (but not the column/indent) in the virtual matrix where the nodes are placed. This purely depends on the y-coordinate and can be an index far greater than the total number of nodes, while eg in the row after the last node, the same index may drop the element as child of the last sub-node, parallel to the last sub-node or parallel to the root node. I haven't found an easy way to tell yet (except for copying the code in the Tree dragDrop handler)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM