flex学习笔记 使用函数,显示实时更新的标签

Posted on 2013-07-29 16:06  诸葛小北  阅读(211)  评论(0编辑  收藏  举报
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
  <s:layout>
      <s:VerticalLayout/>
  </s:layout>
    <fx:Script>
        <![CDATA[
            private function concatenateName(item:Object):String
            {
             return item.firstName + " "+item.lastName;
            }
                
        ]]>
    </fx:Script>
    
    <s:ButtonBar id="buttonBar" labelFunction="concatenateName">
        <mx:ArrayCollection>
            <fx:Object firstName ="马" lastName="楠" email="tahmed@flexinaction.com" phone="18815654512" />
            <fx:Object firstName ="张" lastName="士鑫" email="zhangshixin@xiangm" phone="188156545103" />
            <fx:Object firstName ="马" lastName="楠" email="tahmed@flexinaction.com" phone="18815654512" />
            <fx:Object firstName ="张" lastName="士鑫" email="zhangshixin@xiangm" phone="188156545103" />
            <fx:Object firstName ="马" lastName="楠" email="tahmed@flexinaction.com" phone="18815654512" />
        </mx:ArrayCollection>
    </s:ButtonBar>
</s:Application>
View Code

2使用多列标签函数

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
  <s:layout>
      <s:VerticalLayout/>
  </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.dataGridClasses.DataGridColumn;
            [Bindable]
            public var myAC:ArrayCollection = new ArrayCollection([
                {name:"马楠", username:"manan",dtJoined:"01/02/2008 12:22:11",dtLogin:"02/20/2010 13:33:11"},
                {name:"白小羽", username:"baixiaoyu",dtJoined:"01/02/2008 12:22:11",dtLogin:"02/20/2010 13:33:11"},
                {name:"马a", username:"manan",dtJoined:"01/02/2008 12:22:11",dtLogin:"02/20/2010 13:33:11"},
                {name:"马b", username:"manan",dtJoined:"01/02/2008 12:22:11",dtLogin:"02/20/2010 13:33:11"},
                {name:"马c", username:"manan",dtJoined:"01/02/2008 12:22:11",dtLogin:"02/20/2010 13:33:11"}
            ]);
            
            public function formatDate(row:Object, col:DataGridColumn):String
            {
              var retVal:String ="";
              if(col.dataField =="dtJoined") retVal = dFmt.format(row.dtJoined);
              else if (col.dataField =="dtLogin")
                   retVal = dFmt.format(row.dtLogin);
              return retVal;
            }
            
        ]]>
    </fx:Script>
    <fx:Declarations>
        <mx:DateFormatter id="dFmt" formatString="MM/DD/YY"/>
    </fx:Declarations>
      <mx:DataGrid id="dg" width="500" height="100" dataProvider="{myAC}">
          <mx:columns>
              <mx:DataGridColumn dataField="name" headerText="Name"/>
              <mx:DataGridColumn dataField="username" headerText="Username"/>
              <mx:DataGridColumn dataField="dtJoined" headerText="Joined" labelFunction="formatDate"/>
              <mx:DataGridColumn dataField="dtLogin" headerText="Last login" labelFunction="formatDate"/>
          </mx:columns>
      </mx:DataGrid>
    
</s:Application>
View Code

 

Copyright © 2024 诸葛小北
Powered by .NET 8.0 on Kubernetes