1

我有一个自定义数据网格。我通过属性标准将 hslider 的值传递给它。我有一个用于扩展 GridItemRenderer 的数据网格的外部 itemrenderer。我想根据此属性标准动态更改项目渲染器。要从父组件访问“条件”属性,我想访问 listData 属性。为此,此自定义数据网格实现了 IDropinItemRender。但是 listData 的值为 null。在我的主应用程序中,我正在使用这个数据网格,如下所示。

<components:Mydatagrid dataProvider="{ac}" criteria="{hslider.value}">
<components:columns>
        <s:ArrayList>
            <s:GridColumn dataField="name" headerText="Name"></s:GridColumn>
            <s:GridColumn dataField="age" headerText="Age"></s:GridColumn>
            <s:GridColumn dataField="hair" headerText="Hair" itemRenderer="renderer.GridInlineDynamicRenderer"   />
        </s:ArrayList>
    </components:columns>
</components:Mydatagrid>

这是我的项目渲染器代码。设置数据函数第 2 行的 listData 属性为空。

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                clipAndEnableScrolling="true" implements="mx.controls.listClasses.IDropInListItemRenderer" >
<fx:Script>
    <![CDATA[
        import mx.controls.dataGridClasses.DataGridListData;
        import mx.controls.listClasses.BaseListData;

        import components.Mydatagrid;
        private var _listData:BaseListData;
        public function get listData() : BaseListData
        {
            return _listData;
        }
        public function set listData( value:BaseListData ) : void
        {
            _listData = value;
        }
        protected function button1_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new Event('hairEvent',true));
        }
        override public function set data(value:Object):void
        {
            super.data = value;
            var myListData:DataGridListData = DataGridListData(listData);
            var criteria:Number = (myListData.owner as Mydatagrid).criteria;
            hairClr.setStyle('color',data.hair);
            if(data.age < criteria)
                alpha = 0.4;
            else
                alpha = 1;
        }
    ]]>
</fx:Script>

<mx:HBox> 
    <s:Button click="button1_clickHandler(event)" label="Button" />
    <s:Label id="hairClr" text="Color" />
</mx:HBox>

</s:GridItemRenderer>

listData 在这里为空。但是当我使用带有列表组件的项目渲染器时,它可以工作。项目渲染器的代码是相同的,除了列表项目渲染器扩展了 HBox。此代码的链接是http://www.adobe.com/devnet/flex/articles/itemrenderers_pt3.html。我只是想用数据网格实现相同的功能。

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" implements="mx.controls.listClasses.IDropInListItemRenderer">
<fx:Script>
    <![CDATA[
        import mx.controls.listClasses.BaseListData;

        import components.MyList;

        private var _listData:BaseListData;
        public function get listData() : BaseListData
        {
            return _listData;
        }
        public function set listData( value:BaseListData ) : void
        {
            _listData = value;
        }
        protected function button1_clickHandler(event:MouseEvent):void
        {
            dispatchEvent(new Event('hairEvent',true));
        }
        override public function set data(value:Object):void
        {
            super.data = value;
            var criteria:Number = (listData.owner as MyList).criteria;
            hairClr.setStyle('color',data.hair);
            if(data.age < criteria)
                alpha = 0.4;
            else
                alpha = 1;
        }
    ]]>
</fx:Script>

    <s:Button click="button1_clickHandler(event)" label="Button" />
    <s:Label id="hairClr" text="Color" />
</mx:HBox>
4

0 回答 0