3 Replies Latest reply on Jan 13, 2011 10:25 AM by abhinav1singhal

    Unable to set Labelfield for child element  in List

    abhinav1singhal Level 1

      Hi All,

       

      Below is code I am trying to execute

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" verticalGap="0" xmlns:local="*" height="500" creationComplete="init()" >

       

       

      <mx:Script>

      <![CDATA[

       

       

      private var arr:Array = [{ firstName: "Alex", children:{lastName: "Abc"}}]

       

       

      private function init():void{

      list.dataProvider=arr;

      }

       

      ]]>

       

      </mx:Script>

       

       

       

      <mx:List variableRowHeight="true"

      wordWrap="

      true" id="list"

      labelField="

      chidren.lastName" />

      </mx:Application>

       

       

      I basically want to access the children.lastName on my List. Please let me know how exactly can I do it.

        • 1. Re: Unable to set Labelfield for child element  in List
          saisri2k2 Level 4

          try using labelfunction


          1 person found this helpful
          • 2. Re: Unable to set Labelfield for child element  in List
            Gregory Lafrance Level 6

            labelFunction is the best way to do this. The attached code also shows how to do it with an itemRenderer, though that would not be as efficient.

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application
              xmlns:mx="http://www.adobe.com/2006/mxml"
              layout="horizontal" 
              creationComplete="init()" >
              <mx:Script>
                <![CDATA[
                  private var arr:Array = [{ firstName: "Alex", children:{lastName: "Abc"}}]
                  private function init():void{
                    list1.dataProvider=arr;
                    list2.dataProvider=arr;
                  }
                  
                  private function createLabels(item:Object):String{
                    return item.children.lastName;
                  }
                ]]> 
              </mx:Script>
              <mx:List variableRowHeight="true" 
                wordWrap="true" id="list1">
                <mx:itemRenderer>
                  <mx:Component>
                    <mx:Label text="{data.children.lastName}"/>
                  </mx:Component>
                </mx:itemRenderer>
              </mx:List>
              <mx:List variableRowHeight="true" 
                wordWrap="true" id="list2"
                labelFunction="createLabels"/>
            </mx:Application>
            


            If this post answers your question or helps, please mark it as such. Thanks!

            http://www.stardustsystems.com
            Adobe Flex Development and Support Services

            1 person found this helpful
            • 3. Re: Unable to set Labelfield for child element  in List
              abhinav1singhal Level 1

              Thank you. I was basically truing to get the label informaiton in my Itemrederer. So this should work out.