Flex中如何通过将PopUpMenuButton作为一个XML数据提供源创建一个自定义的labelFunction的label的例子

By Minidxer | April 13, 2009

接下来的例子演示了Flex中如何通过将PopUpMenuButton作为一个XML数据提供源,创建一个自定义的labelFunction的label。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="top"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             private function getTeams(dp:XML, leagueAbbrev:String, divisionLabel:String):XMLList {
  10.                 return dp.league.(@abbrev == leagueAbbrev).division.(@label == divisionLabel).team;
  11.             }
  12.  
  13.             private function popUpMenuButton_labelFunc(item:Object):String {
  14.                 return item.@label + " " + item.@name;
  15.             }
  16.         ]]>
  17.     </mx:Script>
  18.  
  19.     <mx:XML id="mlb" source="mlb.xml" />
  20.  
  21.     <mx:XMLListCollection id="mlbXLC"
  22.             source="{getTeams(mlb, 'NL', 'West')}">
  23.         <mx:sort>
  24.             <mx:Sort>
  25.                 <mx:fields>
  26.                     <mx:SortField name="@label"
  27.                             caseInsensitive="true" />
  28.                 </mx:fields>
  29.             </mx:Sort>
  30.         </mx:sort>
  31.     </mx:XMLListCollection>
  32.  
  33.     <mx:PopUpMenuButton id="popUpMenuButton"
  34.             dataProvider="{mlbXLC}"
  35.             labelFunction="popUpMenuButton_labelFunc" />
  36.  
  37. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Label | No Comments » | Tags: , , ,

Search Posts