隐藏节点在Flex树组件保持孩子可见 [英] Hiding nodes in a flex tree component keeping the children visible
问题描述
我有一个数据提供器采取以下形式的树:
I have a tree with a dataprovider which takes the following form:
<details name="Cars">
<contact_person>aaaa</contact_person>
<list>
<car type="A">
<car name="A1"/>
<car name="A2"/>
</car>
<car type="B">
<car name="B1"/>
<car name="B2"/>
</car>
</list>
</details>
我希望树中的这个样子
I want the tree to be shown like this
Cars
A
A1
A2
B
B1
B2
这是我想隐藏contact_person和列表nodes.Deleting节点从数据提供器不能done.So我所做的就是通过扩展DefaultDataDescriptor.Then覆盖的getChildren方法来创建自定义的树数据描述符,并应用了的filterFunction由super.getChildren.The问题返回的集合是当我隐藏'名单'节点,我不能有子节点,以显示up.So有什么办法,我可以隐藏名单,但显示节点的孩子吗?
That is I want to hide the contact_person and list nodes.Deleting the nodes from the dataprovider cannot be done.So what i did was to create a custom tree data descriptor by extending DefaultDataDescriptor.Then override the getChildren method and applied a filterfunction to the collection returned by super.getChildren.The problem is when i hide the 'list' node I cannot have the child nodes to show up.So is there any way I can hide 'list' but show the children of 'node'?
推荐答案
传递 XML
为的dataProvider
好为演示而当它涉及到真正的产品不能正常工作。最常见的做法是解析 XML
到强类型的对象:
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;
}
用法:
var xml:XML = <details name="Cars">...</details>;
var details:Details = new Details(xml);
var tree:Tree = new Tree();
tree.dataProvider = new ArrayCollection([ details ]);
要简化code我解析XML的构造。变量也可以变成只读属性。
To simplify the code I parse XML in constructors. Variables can be also turned into read-only properties.
这篇关于隐藏节点在Flex树组件保持孩子可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!