Search

'XMLListCollection'에 해당되는 글 1건

  1. 2007.08.03 Flex DataGrid 동적으로 Column 생성하기 - 3

Flex DataGrid 동적으로 Column 생성하기 - 3

Programming/Flex 2007.08.03 17:47 Posted by 파란크리스마스

출처
http://blog.jidolstar.com/17

columninfo.xml


<?xml version="1.0" encoding="iso-8859-1"?>
<root>
  <msg>ok</msg>
  <columninfo>
    <column>
    <name>aaa</name>
   </column>
    <column>
    <name>bbb</name>
   </column>
  </columninfo>
</root>

test.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="448"
 creationComplete="init()">
 
  <mx:HTTPService id="httpdata" url="http://localhost:8080/examples/columninfo.xml" />
 
 <mx:Script>
  <![CDATA[
   import mx.collections.*;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;

   
   public var httpServ:HTTPService;

   [Bindable]
   public var xlcData:XMLListCollection;
   
   public function init():void
   {
    httpServ = new HTTPService();
    request("http://localhost:8080/examples/columninfo.xml");
   }  
   
   public function request(url:String, params:Object=null):void
   {
    this.httpServ.url = url;
    this.httpServ.method = "GET";
    this.httpServ.resultFormat="e4x";
    this.httpServ.addEventListener("result", resultHandler);
    this.httpServ.addEventListener("fault", faultHandler);
    this.httpServ.send(params);
   }
   
   public function resultHandler(e:ResultEvent):void
   {
    var xlData:XMLList = new XMLList(e.result);
    if(xlData.elements("msg").toString()!="ok") {
     mx.controls.Alert.show(xlData.elements("msg").toString(),"Error");
    } else {
     xlcData = new XMLListCollection(xlData.elements("columninfo"));
    }
   
    var columns : Array = grid1.columns;
    var tmpCol : DataGridColumn;
   
//    mx.controls.Alert.show(xlcData.toXMLString());
   
    var item:XML;
       for each(item in xlcData.children()) {
        tmpCol =  new DataGridColumn();
        tmpCol.headerText = item.children().text();
        columns.push(tmpCol);
       }
     
       grid1.columns = columns;      
   }
   
   public function faultHandler(e:FaultEvent):void
   {
    mx.controls.Alert.show("데이타를 읽는 중 에러\n"+e.fault.faultString);
   }
   ]]>
  </mx:Script>  
 
  <mx:DataGrid id="grid1" x="54" y="106" width="280" height="139"/>
  <mx:Button x="54" y="60" label="Button"/>
 
</mx:Application>

신고


 

티스토리 툴바