【问题标题】:Flex tree control only displaying branch elements and not leaf elementsFlex树控件只显示分支元素而不显示叶子元素
【发布时间】:2011-04-16 13:10:21
【问题描述】:

我创建了一个显示树控件的 mxml 页面,但是数据仅显示为分支。即使是叶子的项目也显示为分支。我究竟做错了什么?请帮忙!

谢谢, 音调

<mx:Script>

    <![CDATA[

        import mx.collections.ArrayCollection;

        public function init():void {
            var item:Object;
            var array:Array = new Array();

            var xml:XML =      
                <course>          
                    <section>              
                        <title>Introduction to Actionscript</title>              
                        <section>              
                            <title>Lesson 1: Variables</title>              
                            <section>                  
                                <title>Topic 1: Data types</title>              
                            </section>              
                        </section>          
                    </section>      
                </course>;    



            item = parseStructure(xml);  

            array.push(item);

            var arrColl:ArrayCollection = new ArrayCollection(array);

            Tree.dataProvider = arrColl;

        }


        private function parseStructure(xml:XML):Object{    
            var obj:Object = new Object();
            obj.label = xml.title;
            if(xml.section != null) {
                obj.children = new ArrayCollection();
                for each (var child:XML in xml.section) {
                    obj.children.addItem(parseStructure(child));         
                }
            }

            return obj;

        }

    ]]>


</mx:Script>


<mx:HBox>
    <mx:Tree id="Tree" width="300"/>       
</mx:HBox>

【问题讨论】:

    标签: apache-flex flash


    【解决方案1】:

    是的,对象的children属性必须为null,如果它是一个空集合是不够的。 hasChildren 属性上的Reference 对此并不十分清楚,至少对我而言:)

    对于其他对象,如果节点具有非空子字段,则返回 true。

    【讨论】:

      【解决方案2】:

      我怀疑当您调试代码时,您会看到 xml.section 不为空。 flex 中的 XML 处理有时很愚蠢,并且试图提供帮助。当 xml.section 为空时,它可能会做一些愚蠢的事情,比如返回整个 XML 对象......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 2017-06-29
        • 1970-01-01
        • 2016-05-06
        • 1970-01-01
        • 2012-01-12
        • 2016-08-21
        相关资源
        最近更新 更多