Flex3 - 渲染器ItemRenderer里获取表格及列等对象方法
在render内部如果需要获取对应的表格或者列信息等,可进行如下操作:
对应ItemRenderer实现
//获取绑定字段 var dataField:String = (this.listData as DataGridListData).dataField //获取列索引和行索引 var columnIndex:int = this.listData.columnIndex; var rowIndex:int = this.listData.rowIndex; //获取表格 var datagrid:DataGrid = this.listData.owner as DataGrid; //获取该render要显示的值 var str:String = this.listData.label;
对应ItemRenderer实现
package datagrid { import mx.controls.listClasses.BaseListData; import mx.controls.listClasses.IDropInListItemRenderer; import mx.controls.listClasses.IListItemRenderer; import mx.core.IDataRenderer; import mx.core.UIComponent; import mx.events.FlexEvent; import mx.managers.ILayoutManagerClient; import mx.styles.IStyleClient; /** * 列表render基类,任何render都可以继承该类 */ public class BaseGridItemRenderer extends UIComponent implements IDataRenderer, IDropInListItemRenderer, ILayoutManagerClient, IListItemRenderer, IStyleClient { /** * 由 IDataRenderer 接口定义的 data 属性实现 */ private var _data:Object; /** * 由 IDropInListItemRenderer 接口定义的 listData 属性实现 */ private var _listData:BaseListData; public function BaseGridItemRenderer() { super(); } public function set data(value:Object):void { _data = value ; invalidateProperties(); dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE)); } [Bindable("dataChange")] public function get data():Object { return _data ; } [Bindable("dataChange")] public function get listData():BaseListData { return _listData; } /** * @private */ public function set listData(value:BaseListData):void { _listData = value; } } }