2 Replies Latest reply on Jun 8, 2007 9:38 AM by dishmael

    ArrayCollection Binding

    dishmael Level 1
      I have an ArrayCollection I'm binding to a DataGrid and everything seems to work except for one column which is an object under the ArrayCollection. Basically, it looks like this in XML

      <foo>
      <cat/>
      <dog/>
      <fruit>
      <apple/>
      <orange/>
      </fruit>
      </foo>
      <foo>
      <cat/>
      <dog/>
      <fruit>
      <apple/>
      <orange/>
      </fruit>
      </foo>

      I can access the animals in the DataGrid but I can't figure out how to access the fruits. I tried this in the DataGridColumn dataField: dataField="fruit.apple" but that didn't work. How do you access children of the top node in the DataGrid?
        • 1. Re: ArrayCollection Binding
          dimival Level 1
          I think that you need to use a labelFunction:

          <mx:DataGridColumn labelFunction="getFruits"/>

          public function getFruits(item:Object, column:DataGridColumn):String
          {
          // Where item contains the DataGrid item object,
          }

          I am not sure what are you trying to show in that column but as you can see in the getFrutis function you have access to your item (foo in this case), so part from there and show the value that you want to. Remember the function's signature must be like this one and you must return an string


          • 2. Re: ArrayCollection Binding
            dishmael Level 1
            I'll give that a try. The intended output (based on the XML example) in the DataGrid should be...

            Cat | Dog | Apple
            Cat | Dog | Apple

            I can get Cat and Dog, but I can't seem to get Apple because its a child of Fruit. I'll try the labelFunction and see if that works. Thanks!