Flex Datagrid ItemRenderer问题

时间:2011-03-22 06:12:40

标签: flash flex

我有一个datagrid,其中有两列,对于第二列,我使用Datagrid作为ItemRenderer,它再次由2个cols组成,在第二列中我再次使用Datagrid作为ItemRenderer。

代码如下 1.Test.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="500"
                width="500" layout="absolute" applicationComplete="application1_applicationCompleteHandler(event)">
    <mx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function application1_applicationCompleteHandler(event:FlexEvent):void
            {
                PopulateListForReport("http://localhost/BusinessWorks/model/AjaxRequestHandler.php?action=TestXmlForGrid");
            }

        ]]>
    </mx:Script>
    <mx:Panel title="Tutorials" width="100%" height="100%" layout="absolute">
        <mx:DataGrid id="SalesDataGrid" width="100%" height="300" horizontalScrollPolicy="auto">
            <mx:columns>
                <mx:DataGridColumn headerText="Zones" width="75" dataField="Zones.Zone.@name" />
                <mx:DataGridColumn headerText="Apr 2010 - Mar 2011" itemRenderer="Year1" />             
            </mx:columns>
        </mx:DataGrid>      
    </mx:Panel>


<mx:Script><![CDATA[

    import UICore.UIButton;

    import UIPanel.UIPanel;

    import flash.events.Event;

    import mx.collections.ArrayCollection;
    import mx.collections.XMLListCollection;
    import mx.controls.*;
    import mx.events.DropdownEvent;
    import mx.events.ListEvent;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.HTTPService;
    import mx.utils.ArrayUtil;  


    var ResultXml:XML;

    public function PopulateListForReport(szURL:String):void {
    var service:HTTPService;
    service = new HTTPService();
    service.url = szURL;
    service.method = "POST";
    service.useProxy=false;
    service.resultFormat="e4x"
    service.contentType="application/x-www-form-urlencoded";
    service.addEventListener("result", GetData1);
    service.addEventListener("fault", Error1);
    service.send();
    }

    public function GetData1(event:ResultEvent):void {
    ResultXml = XML(event.result);
    SalesDataGrid.dataProvider = ResultXml;
    }

    public function Error1(event:FaultEvent):void {

        var faultstring:String = event.fault.faultString;
        Alert.show(faultstring + "FAULT CODE: " + event.fault.faultCode + "\n\n" + "FAULT DETAIL: " + event.fault.faultDetail + "\n\n");
    }
]]></mx:Script> 

</mx:Application>

2.Year1.mxml(第二列的ItemRenderer)

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
             showHeaders="false" xmlns:local="*" xmlns:s="library://ns.adobe.com/flex/spark">
    <mx:Script><![CDATA[
        import mx.collections.XMLListCollection;
        import mx.controls.Alert;
        public var ResultData:String;

        override public function set data(value:Object):void
        {
            try
            {
                super.data = value;
                this.dataProvider = this.data.Zones.Categories.Category;
                /*var itemRenderer:ClassFactory = new ClassFactory(Month1);
                itemRenderer.properties = {Data:this.data};
                Months.itemRenderer = itemRenderer; 
                Alert.show(ResultData);*/
            }catch(e:Error)
            {
                Alert.show("error"+e);
            }
        }


    ]]></mx:Script>
    <mx:columns>
        <mx:DataGridColumn id="Categories" dataField="@name"/>
        <mx:DataGridColumn id="Months" itemRenderer="Month1"/>
    </mx:columns>   
</mx:DataGrid>
  1. 然后是第三个Month1.mxml
  2. 问题是我如何从Month.mxml中的T​​est.mxml中获取完整的Xml,正如您从上面的代码中看到的那样(在Year1.mxml中)我已将dataprovider设置为Categories

    等待有人回复

0 个答案:

没有答案