简体   繁体   English

弹性树控件拖放.item位置

[英]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. 我想将哪个node(id)放到哪个节点内。

1]if i drag "Cat1" node inside "Cat3",i want to identify ids of siblings of "cat1",and "cat3". 1]如果我将“ Cat1”节点拖到“ Cat3”内,我想标识“ cat1”和“ cat3”的同级ID。

2]in general i want to know the ids of current element being moved along with 2]总的来说,我想知道当前元素的ID与
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. 3]同样,当移到“ cat3”之外时,“ cat4”也想知道它的位置及其同级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暂时解决了问题
dragComplete="handleDragComplete(event) 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. 当拖动完成后,我从树中获取更改的dataprovider,然后在更改后的dataprovider中递归搜索“拖放项”(“ id” +“ label”)以找到其在树中的位置。 "id" of the node in which the selected node is dropped(parent node). 所选节点所在的节点(父节点)的“ id”。 and fire the save to database api. 并触发保存到数据库api。

anyone has better options. 任何人都有更好的选择。 pls reply 请回复

thanks :) 谢谢 :)

The DragEvent contains a dragSource element. DragEvent包含dragSource元素。 It contains the element(s) being dragged. 它包含要拖动的元素。 In case of a tree, it is of type "treeItems". 如果是树,则其类型为“ 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. 拖动树节点时,只有一个元素,即items[0]可以很容易地位于(更改的)树内部。

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. “ calculateDropIndex()”函数仅计算放置节点的虚拟矩阵中的行(但不计算列/缩进)。 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. 这纯粹取决于y坐标,并且可以是远远大于节点总数的索引,而例如在最后一个节点之后的行中,相同的索引可能会将元素作为最后一个子节点的子元素删除,与最后一个子节点或与根节点平行的子节点。 I haven't found an easy way to tell yet (except for copying the code in the Tree dragDrop handler) 我还没有找到一种简单的方法(除了在Tree dragDrop处理程序中复制代码)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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