Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 树不';将子节点添加到空的扩展节点时刷新_Actionscript 3_Actionscript_Air_Flex4 - Fatal编程技术网

Actionscript 3 树不';将子节点添加到空的扩展节点时刷新

Actionscript 3 树不';将子节点添加到空的扩展节点时刷新,actionscript-3,actionscript,air,flex4,Actionscript 3,Actionscript,Air,Flex4,我正在将mx:Tree绑定到父类的对象。父项具有子项的数组集合。当我展开一个空节点并添加一些子节点时,它不会刷新,直到我折叠并展开此节点。如果节点已经有子节点,则一切正常,新节点立即出现。我怎样才能修好它 <?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

我正在将mx:Tree绑定到父类的对象。父项具有子项的数组集合。当我展开一个空节点并添加一些子节点时,它不会刷新,直到我折叠并展开此节点。如果节点已经有子节点,则一切正常,新节点立即出现。我怎样才能修好它

    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx">

        <fx:Script>
            <![CDATA[
    import mx.collections.ArrayCollection;
                [Bindable]
                public var selectedNode:Parent;

                [Bindable]
                public var treeData:ArrayCollection = new ArrayCollection();

                public function treeChanged(evt:Event):void {
                    selectedNode = Tree(evt.target).selectedItem as Parent;
                }

                public function btnClick():void 
                {
                    if (selectedNode)
                    {
                        (selectedNode as Parent).children.addItem(new Parent());
                    }
                    else 
                    {
                        treeData.addItem(new Parent());
                    }

                }
            ]]>
        </fx:Script>


        <s:Panel title="Halo Tree Control Example"
                width="75%" height="75%"
                horizontalCenter="0" verticalCenter="0">
            <s:VGroup left="10" right="10" top="10" bottom="10">
                <mx:Button click="{btnClick()}" label="Add"></mx:Button>

                <mx:HDividedBox width="100%" height="100%">
                    <mx:Tree id="myTree" width="50%" height="100%" labelField="@label"
                            showRoot="false" dataProvider="{treeData}" change="treeChanged(event);"/>
                    <s:TextArea height="100%" width="50%"
                            text="Selected Item: {selectedNode}"/>
                </mx:HDividedBox>
            </s:VGroup>

        </s:Panel>
    </s:WindowedApplication>

您可以使用
树的
invalidateList()
方法告诉树在下一次生命周期更新时刷新自身:

public function btnClick():void 
{
    if (selectedNode)
    {
        (selectedNode as Parent).children.addItem(new Parent());
        myTree.invalidateList();
    }
    else 
    {
        treeData.addItem(new Parent());
    }
}
public function btnClick():void 
{
    if (selectedNode)
    {
        (selectedNode as Parent).children.addItem(new Parent());
        myTree.invalidateList();
    }
    else 
    {
        treeData.addItem(new Parent());
    }
}