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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以将查询结果列表展示到一个单选框组件。具体的实现步骤如下: 创建一个单选框组件,可以使用 flex 自带的 RadioButtonGroup 组件或者自定义单选框组件。 将查询结果列表绑定到单选框组件的dataProvider属性上。例如: 复制 <s:RadioButtonGroup id="radioGroup" dataProvider="{queryResultList}" /> 在单选框组件设置 labelFunction 属性,用于指定每个单选框的显示文本。例如: 复制 <s:RadioButtonGroup id="radioGroup" dataProvider="{queryResultList}" labelFunction="getResultLabel" /> 其 getResultLabel 是一个自定义的函数,用于返回每个单选框的显示文本。 在 getResultLabel 函数,根据查询结果列表的数据,构造每个单选框的显示文本。例如: 复制 private function getResultLabel(item:Object):String { return item.name + " - " + item.value; } 上述代码,假设查询结果列表每个元素都有 name 和 value 两个属性,getResultLabel 函数将这两个属性拼接起来作为每个单选框的显示文本。 最后,为单选框组件添加事件监听器,用于在用户选择单选框时执行相应的操作。例如: 复制 <s:RadioButtonGroup id="radioGroup" dataProvider="{queryResultList}" labelFunction="getResultLabel" change="onRadioChange(event)" /> 上述代码,onRadioChange 函数是一个自定义的事件处理函数,用于响应单选框选择事件并执行相应的操作。选之后要保存,onRadioChange(event)要怎么写
最新发布
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值