Hiding nodes in a flex tree component keeping the children visible

流过昼夜 提交于 2019-12-02 09:50:13

Passing XML as a dataProvider is good for demos and does not work when it comes to the real product. The common practice is parsing the XML into strong-typed objects:

public class Details 
{ 
    public function Details(xml:XML)
    {
        label = xml.@name;
        var childrenArray:Array = [];
        for each (var carNode:XML in xml.list.car)
        {
            childrenArray.push(new CarType(carNode));
        }
        children = new ArrayCollection(childrenArray);
    }

    [Bindable]
    public var label:String;

    [Bindable]
    public var children:ArrayCollection /* of CarType */;
}

public class CarType
{
    public function CarType(xml:XML)
    {
        label = xml.@type;
        var childrenArray:Array = [];
        for each (var carNode:XML in xml.car)
        {
            childrenArray.push(new Car(xml));
        }
        children = new ArrayCollection(childrenArray);
    }

    [Bindable]
    public var label:String;

    [Bindable]
    public var children:ArrayCollection /* of Car */;
}

public class Car
{
    public function Car(xml:XML)
    {
        label = xml.@name;
    }

    [Bindable]
    public var label:String;
}

Usage:

var xml:XML = <details name="Cars">...</details>;
var details:Details = new Details(xml);
var tree:Tree = new Tree();
tree.dataProvider = new ArrayCollection([ details ]);

To simplify the code I parse XML in constructors. Variables can be also turned into read-only properties.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!