您有两种选择来解决这个问题。要么创建自己的实现IHierarchicalData
(它不必扩展HierarchicalData
,在这种特殊情况下不会有太多可以重用的代码),要么稍微改变处理数据的方式,使其符合标准用例:
[Bindable] // make it bindable so that the HierarchicalCollectionView gets notified when the object changes
class Foo // your data class
{
// this constructor is needed to easily create the rootItems below
public function Foo(children:ArrayCollection = null)
{
this.children = children;
}
// use an ArrayCollection which dispatches an event if one of its children changes
public var children:ArrayCollection;
// all your other fields
}
// Create your rootItems like this. Each object can contain a collection of children
// where each of those can contain children of its own and so forth...
var rootItems:ArrayCollection = new ArrayCollection([
new Foo(
new ArrayCollection([
new Foo(),
new Foo(),
new Foo(
new ArrayCollection([
// ...
]),
new Foo()
])
),
new Foo(
// ...
),
// ...
]);
// Create the HierarchicalData and HierachicalCollectionView
var hd:IHierarchicalData = new HierarchicalData(rootItems);
[Bindable]
var hcv:IHierarchicalCollectionView = new HierarchicalCollectionView(hd);
然后你可以在你的 ADG 中使用hcv
asdataProvider
并使用它的方法来添加和删除项目。每当您添加、删除或更新项目时,ADG 都会刷新。
我建议您以标准方式进行操作,除非那确实不可能。