在 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>
我希望树像这样显示
Cars
A
A1
A2
B
B1
B2
那是我想隐藏 contact_person 和 list 节点.无法从数据提供者中删除节点.所以我所做的是通过扩展 DefaultDataDescriptor 创建自定义树数据描述符.然后覆盖 getChildren 方法并应用过滤器功能到 super.getChildren 返回的集合.问题是当我隐藏列表"节点时,我无法显示子节点.那么有什么办法可以隐藏列表"但显示节点"的子节点?
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 ]);
为了简化代码,我在构造函数中解析 XML.变量也可以变成只读属性.
To simplify the code I parse XML in constructors. Variables can be also turned into read-only properties.
这篇关于在 flex 树组件中隐藏节点以保持子节点可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!