FLEX中labelFunction的用法.

MXML

<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="top"
        backgroundColor
="white" >

    
< mx:Script >
        
<![CDATA[
            private function getTeams(dp:XML, leagueAbbrev:String, divisionLabel:String):XMLList {
                return dp.league.(@abbrev == leagueAbbrev).division.(@label == divisionLabel).team;
            }

            private function popUpMenuButton_labelFunc(item:Object):String {
                return item.@label + " " + item.@name;
            }
        
]]>
    
</ mx:Script >

    
< mx:XML  id ="mlb"  source ="mlb.xml"   />

    
< mx:XMLListCollection  id ="mlbXLC"
            source
=" {getTeams(mlb, 'NL', 'West')} " >
        
< mx:sort >
            
< mx:Sort >
                
< mx:fields >
                    
< mx:SortField  name ="@label"
                            caseInsensitive
="true"   />
                
</ mx:fields >
            
</ mx:Sort >
        
</ mx:sort >
    
</ mx:XMLListCollection >

    
< mx:PopUpMenuButton  id ="popUpMenuButton"
            dataProvider
=" {mlbXLC} "
            labelFunction
="popUpMenuButton_labelFunc"   />

</ mx:Application >


mlb.xml

 

   <? xml version="1.0" encoding="utf-8"  ?>  
<!--   http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/ 
  
-->  
< root >
< league  label ="American League"  abbrev ="AL" >
< division  label ="West" >
  
< team  label ="Los Angeles"  name ="Angels of Anaheim"   />  
  
< team  label ="Seattle"  name ="Mariners"   />  
  
< team  label ="Oakland"  name ="Athletics"   />  
  
< team  label ="Texas"  name ="Rangers"   />  
  
</ division >
< division  label ="Central" >
  
< team  label ="Cleveland"  name ="Indians"   />  
  
< team  label ="Detroit"  name ="Tigers"   />  
  
< team  label ="Minnesota"  name ="Twins"   />  
  
< team  label ="Chicago"  name ="White Sox"   />  
  
< team  label ="Kansas City"  name ="Royals"   />  
  
</ division >
< division  label ="East" >
  
< team  label ="Boston"  name ="Red Sox"   />  
  
< team  label ="New York"  name ="Yankees"   />  
  
< team  label ="Toronto"  name ="Blue Jays"   />  
  
< team  label ="Baltimore"  name ="Orioles"   />  
  
< team  label ="Tampa Bay"  name ="Rays"   />  
  
</ division >
  
</ league >
< league  label ="National League"  abbrev ="NL" >
< division  label ="West" >
  
< team  label ="Arizona"  name ="Diamondbacks"   />  
  
< team  label ="Colorado"  name ="Rockies"   />  
  
< team  label ="San Diego"  name ="Padres"   />  
  
< team  label ="Los Angeles"  name ="Dodgers"   />  
  
< team  label ="San Francisco"  name ="Giants"   />  
  
</ division >
< division  label ="Central" >
  
< team  label ="Chicago"  name ="Cubs"   />  
  
< team  label ="Milwaukee"  name ="Brewers"   />  
  
< team  label ="St. Louis"  name ="Cardinals"   />  
  
< team  label ="Houston"  name ="Astros"   />  
  
< team  label ="Cincinnati"  name ="Reds"   />  
  
< team  label ="Pittsburgh"  name ="Pirates"   />  
  
</ division >
< division  label ="East" >
  
< team  label ="Philadelphia"  name ="Phillies"   />  
  
< team  label ="New York"  name ="Mets"   />  
  
< team  label ="Atlanta"  name ="Braves"   />  
  
< team  label ="Washington"  name ="Nationals"   />  
  
< team  label ="Florida"  name ="Marlins"   />  
  
</ division >
  
</ league >
  
</ root >

来自:http://blog.flexexamples.com/2008/02/21/creating-a-custom-label-function-on-a-flex-popupmenubutton-control/

你可能感兴趣的:(function)