为了使用treeGrid,通常你需要定义自己的DataDescriptor和data model,下面是一个案例.
public class HierarchySearchResultVO
{
public function HierarchySearchResultVO(){
this._id=UIDGenerator.createUID();
}
/**
* An unique identifier of the created HierarchySearchResultVO object.
*/
[Transient]
private var _id:String;
public function get id():String{
return this._id;
}
public function set id(value:String):void{
this._id=value;
}
/**
* If not a summary record, it should have a parent.
*/
[Transient]
public var parent:HierarchySearchResultVO;
/**
* Indicates whether the record shows at summary level or detail level in a treeGrid.</br>
* True denotes a summary record, false denotes detail record, default is false.
*/
[Transient]
public var isSummaryRecord:Boolean=false;
/**
* Only applicable to summary record.
* Indicates whether the summary record has got its children from server.</br>
* True denotes the summary record has already got its children from serve;</br>
* False denotes not yet.
*/
[Transient]
public var hasChildrenReturned:Boolean=false;
/**
* Indicates whether the summary record itself or detail record is checked,
* isAllSeleceted and isPartSelected are used to indicate whether the children of
* the summary record are checked, they don't indicate the check status of the summary record itself.
*/
[Transient]
public var isSelected:Boolean=false;
/**
* Indicates whether all the children records of a summary record have been checked,
* only used for a summary record, should be exclusive with isPartSelected.
* If isAllSelected=false and isPartSelected=false means none of the children records have been checked.
*/
//[Transient]
//public var isAllSelected:Boolean=false;
/**
* Indicates only part of the children records of a summary record have been checked,
* only used for a summary record, should be exclusive with isAllSelected.
* If isAllSelected=false and isPartSelected=false means none of the children records have been checked.
*/
[Transient]
public var isPartSelected:Boolean=false;
/**
* This property name should be same as what we defined in HierarchySearchResultDataDescriptor,
* element should be object of HierarchySearchResultVO, not SearchResultVO.
*/
[Transient]
public var childrenCollection:ArrayCollection;
public var searchResultVO:SearchResultVO;
}
/**
* Used to parse the data of the TreeGrid
*/
public class HierarchySearchResultDataDescriptor extends DefaultDataDescriptor
{
public function HierarchySearchResultDataDescriptor()
{
super();
}
override public function getChildren(node:Object, model:Object=null):ICollectionView
{
return node.childrenCollection;
}
override public function hasChildren(node:Object, model:Object=null):Boolean
{
return node != null && node.childrenCollection != null && (node.childrenCollection as ArrayCollection) != null && (node.childrenCollection as ArrayCollection).length > 0;
}
override public function isBranch(node:Object, model:Object=null):Boolean
{
return (node as HierarchySearchResultVO).isSummaryRecord;
}
override public function getData(node:Object, model:Object=null):Object
{
return node;
}
}