flex中使用DataGrid显示xml 之二

1,使用了状态

2,使用了datagrid的编辑格式,日期格式化,

3,使用datagrid列中包含其他组件的方法 

4,使用了xml转换ArrayCollection 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="bookDate.send()">
<mx:states>
<mx:State name="nr">
<mx:AddChild position="lastChild">
<mx:Text text="Text" width="571" height="380" id="ns" enabled="false" alpha="0.38"/>
</mx:AddChild>
<mx:RemoveChild target="{datagrid1}"/>
</mx:State>
</mx:states>
<mx:Script>
          <![CDATA[
           import mx.messaging.channels.StreamingAMFChannel;
           import mx.controls.dataGridClasses.DataGridColumn;
               import mx.collections.*;
               import mx.rpc.events.*;
               [Bindable]
               private var bookstock:ArrayCollection;
               private function bookHandler(evt:ResultEvent):void
               {
               bookstock=evt.result.NewDataSet.NewView;
               test.dataProvider=bookstock;
               }
               private function dateformat(dateItem:Object,Time:DataGridColumn):String
               {
               return ptime.format(dateItem.Time);
               }

         ]]>
     </mx:Script>
<mx:HTTPService id="bookDate" url="huiyuan.xml" result="bookHandler(event)" />

<mx:DataGrid width="474" id="test"  >
</mx:DataGrid>
 


<mx:DataGrid width="825.5" height="100%" dataProvider="{bookDate.lastResult.NewDataSet.NewView}"  enabled="true" id="datagrid1"  editable="true">
<mx:columns>
<mx:DataGridColumn headerText="序列号" dataField="id"  width="100" fontSize="14"/>
<mx:DataGridColumn headerText="姓名" dataField="name"/>
<mx:DataGridColumn headerText="电话" dataField="phone"/>
<mx:DataGridColumn headerText="邮件" dataField="mail"/>
<mx:DataGridColumn headerText="时间" dataField="Time" labelFunction="dateformat"/>
<mx:DataGridColumn headerText="reviews" itemEditor="vtest" editable="true" >
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:DateFormatter id="ptime" formatString="MM YYYY" />

<mx:Style source="fcss.css"/>
     
</mx:Application>

posted @ 2010-10-11 16:43  fsl  阅读(1521)  评论(2编辑  收藏  举报