DataGrid中labelFunction实例学习.

DataGrid中labelFunction实例学习.
示例:

代码:
<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="vertical" >
  
< mx:Script >
    
<![CDATA[
      [Bindable]
      public var myDataProvider:Array = [  125000000.99,
                1700000000.01, 
                984561321483.56,
                0.99,
                5.75,
                31400000000.01];
      
      public function myLabelFunction(item:Object, column:DataGridColumn):String
      {
        var amount:String = item.toString();
        var dollars:String = amount.split(".")[0];
        var dollarDigitCount:Number = dollars.toString().length;
        
        var value:String;
        
        if (dollarDigitCount >= 7 && dollarDigitCount <= 9)
        {
          value = dollars.slice(0, -6) + " Million";
        }
        else if (dollarDigitCount >= 10 && dollarDigitCount <= 12)
        {        
          value = dollars.slice(0, -9) + " Billion";
        }
        else if (dollarDigitCount >= 13)
        {
          value = dollars.slice(0, -12) + " Trillion";
        }
        else
        {
          value = item.toString();
        }
        
        return "$" + value;
      }
    
]]>
  
</ mx:Script >
 
  
< mx:DataGrid  id ="dg"  dataProvider =" {myDataProvider} "   >
    
< mx:columns >
      
< mx:DataGridColumn  headerText ="Click To Sort"  labelFunction ="myLabelFunction" />
    
</ mx:columns >
  
</ mx:DataGrid >
  
  
< mx:TextInput  id ="textInput"  text =" {dg.selectedItem} " />
  
</ mx:Application >

你可能感兴趣的:(function)