views:

310

answers:

2

i used advance datagrid of dataProvider as HierarchicalData . it's an my array collection strature

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}]},
              
            ]);

i want to get particular data like matches details and count which one is (isEnable==true) value . so convert HierarchicalCollectionView to Array like

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++;

        }


       }

It shows only country details but if i tried matches and isEnable not found in array . How can i found is isEnable and matches details ? Please refer me

A: 

You are still only testing the top level children in your loop. Change it to,

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++;
        }
    }
}

This way, you are looping through the children of each of the top level objects to reach the match objects.

You should probably think about making a typed object for both your Country and Match objects, you'll be able to encapsulate this type of behaviour much easier.

Gregor Kiddie
oh and Yay for cricket! First cricket related question I've seen on SO!
Gregor Kiddie
ya sure !! thank you for your valued information Gregor Kiddie
R.Vijayakumar
it's has two chlidren then how do to that
R.Vijayakumar
for each ( match : Object in hArray[i].children.children ) { if ( match.isEnable ) { count1++;}is it possiable can do that
R.Vijayakumar
you'd be better off writing a recursive function that checked if the object had children and then calling the same function with those children... that would cope with any level of nesting for the children.
Gregor Kiddie
A: 
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);
     }
    }
}
Su.E