1

因此,Flex 为其数据馈送控件的用户操作提供了出色的 API,但是,在我的一生中,我无法弄清楚如何在用户玩完数据后将数据从控件中取出。具体来说,我在 Tree 组件上启用了 dragMove 控件,但我不知道如何将用户发起的更改恢复为可以写回数据库的 XML 数据。

当用户重新排序树时,dataProvider 中没有注册任何更改,如果 dataDescriptor 正在注册这些更改,我不知道如何将数据取回。dataDescriptor 方法 getData() 调用节点参数....哪个节点?节点来自自己的dataProvider??我不明白。有任何想法吗?

4

3 回答 3

1

I believe what you have to do is listen to the dragOver event and manipulate the resulting data in that handler. Drag drops support is mainly for transferring from one list control to another control.

于 2009-04-07T00:38:12.493 回答
1

CookieOfFortune is correct: if you are trying to do more than just nominal drag&drop (e.g. detect changes and propagate them to a DB), you'll probably need to work with the drag & drop interface on the tree.

You can also set a listener to detect when the tree has changed (e.g. a select has occurred). This works for both selects and drag & drops.

Not knowing what you're doing, here's a little code. I only overrode dragComplete just to show how an event can be detected.

<?xml version='1.0'?>
<mx:Application xmlns:mx='http://www.adobe.com/2006/mxml' backgroundGradientColors='[0xFFFFFF,0xAAAAAA]'>

    <mx:Script>
        <![CDATA[
        import mx.events.DragEvent;
        import mx.controls.Alert;

        [Bindable]
        private var treeData:XML =
            <root>
                <node label="foo">
                    <node label="bar" />
                </node>
                <node label="baz">
                    <node label="buzz">
                        <node label="foobar" />
                    </node>
                </node>
            </root>;

        private function detectChange(event:Event):void {
            Alert.show("change detected!");
        }
        private function detectDragComplete(event:DragEvent):void {
            Alert.show("drag completed!");
        }

        ]]>
    </mx:Script>

  <mx:Tree id="tree" labelField="@label" 
           dataProvider="{treeData.node}" width="200"
           dragEnabled="true"
           dropEnabled="true"
           dragMoveEnabled="true"
           dragComplete="detectDragComplete(event)"
           change="detectChange(event)" />
</mx:Application>

Here are some links with some more information regarding drag&drop functionality in various controls:

于 2009-04-07T02:15:39.623 回答
0

我不得不做同样的事情。我在 DataProvider 上为 CollectionEvent.COLLECTION_CHANGE 事件上的树设置了一个事件侦听器。

public function init():void{

        //watch the tree dataProvider changes.
        BindingUtils.bindSetter(setUpDataChangeListner,_tree,["dataProvider"]);
    }

    public function setUpDataChangeListner(value:XMLListCollection):void{
        //set up the event listener for the dataProvider as long as it is not null
        if(value)
            value.addEventListener(CollectionEvent.COLLECTION_CHANGE,onTreeChanged,false,0,true);
    }

    public function onTreeChanged(event:CollectionEvent):void{
        trace("fun");
    }
于 2009-05-08T15:41:54.133 回答