我使用dataProvider的高级datagrid作为HierarchicalData。这是我的阵列集合论文
private var groupList:ArrayCollection = new ArrayCollection([
{Country:'India', children:[
{Matches:'India Test series 1',isEnable:false},
{Matches:'India Test series 2',isEnable:false},
{Matches:'India Test series 3',isEnable:false}]},
{Country:'Australia', children:[
{Matches:'Australia Test series 1',isEnable:false},
{Matches:'Australia Test series 2',isEnable:false},
{Matches:'Australia Test series 3',isEnable:false}]},
{Country:'japan', children:[
{Matches:'Australia Test series 1',isEnable:false},
{Matches:'Australia Test series 2',isEnable:false},
{Matches:'Australia Test series 3',isEnable:false}]},
]);
我希望获得匹配详细信息等特定数据,并计算哪一个是(isEnable == true)值。所以将HierarchicalCollectionView转换为数组,如
var hCollView:HierarchicalCollectionView = updategrid.dataProvider as HierarchicalCollectionView;
var hCollData:HierarchicalData = hCollView.source as HierarchicalData;
var hArrayColl:ArrayCollection = hCollData.source as ArrayCollection;
var hArray:Array = hArrayColl.source as Array;
for(var i:Number=0;i<hArray.length;i++)
{
Alert.show(hArray[i].Country);
if(hArray[i].isEnable=="true")
{
count1++;
}
}
它仅显示国家/地区详细信息,但如果我尝试匹配并且未在数组中找到isEnable。我如何找到isEnable并匹配详细信息?请转介我
答案 0 :(得分:0)
您仍在测试循环中的顶级子级。将其更改为,
for( var i : Number = 0; i < hArray.length; i++ ) {
Alert.show( hArray[i].Country );
for each ( match : Object in hArray[i].children ) {
if ( match.isEnable ) {
count1++;
}
}
}
这样,您循环遍历每个顶级对象的子节点以到达匹配对象。
您应该考虑为Country和Match对象创建一个类型化对象,您将能够更轻松地封装此类行为。
答案 1 :(得分:0)
public static function convertHCollViewToArrColl(hcoll: HierarchicalCollectionView): ArrayCollection
{
var arrcoll: ArrayCollection = new ArrayCollection();
fectchNodeFromHColl(hcoll, null, arrcoll);
return arrcoll;
}
internal static function fectchNodeFromHColl(hcoll: HierarchicalCollectionView, node: Object, targetArrayColl: ArrayCollection): void
{
var subNodes: ICollectionView;
if(node == null)
{
subNodes = (hcoll.source as HierarchicalData).source as ArrayCollection;
}else
{
targetArrayColl.addItem(node);
subNodes = hcoll.getChildren(node);
}
if(subNodes !=null && subNodes.length > 0)
{
for each(var n: Object in subNodes)
{
fectchNodeFromHColl(hcoll, n, targetArrayColl);
}
}
}