2 Replies Latest reply on Sep 3, 2010 9:44 AM by Arun Ganesh

    count of fields in ArrayCollection

    Devtron Level 3

      Hello,

       

      Let's say I have an ArrayCollection as so:

       

                [Bindable] 
                private var ItemDGDataProvider:ArrayCollection = new ArrayCollection([ 
                    {name:"Item1",value:"21",qty:"3",cost:"12.21", apples: "1"}, 
                    {name:"Item2",value:"20",qty:"4",cost:"12.22", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item3",value:"22",qty:"5",cost:"12.23", apples: "1"}, 
                    {name:"Item4",value:"23",qty:"2",cost:"12.24", apples: "1"} 
                    ]);

       


      How can I get the count of items? I do not need the total count, I need the field count, which in this case would be 5.

       

      What is the code to do that?

       

      I do not need the ArrayCollection.length, but instead, need ArrayCollection.FieldCount or something similar?

        • 1. Re: count of fields in ArrayCollection
          Arun Ganesh Level 3

          Hi,

          Hopefully this will help you.

           

          if(ItemDGDataProvider!=null && ItemDGDataProvider.length>0)
                              Alert.show(getPropertyCount(ItemDGDataProvider.getItemAt(0))+"");

           

          private function getPropertyCount(obj:Object):Number{                
                          var count:int = 0;
                          for each (var prop:Object in obj)
                          {
                              count++;
                          }
                          return count;

          }

          • 2. Re: count of fields in ArrayCollection
            Flex harUI Adobe Employee

            Probably something like ObjectUtil.getClassInfo().properties.length