有人能帮我完成这个吗?//用于 mx:DataGrid [工作代码] 的示例 itemRenderer<![CDATA[导入 mx.events.FlexEvent;导入 scripts.valueObjects.CellRendererVO;私有变量 _cellRenderer:CellRendererVO = 新 CellRendererVO();[可绑定]私有变量_lineColor:uint = 0xFF0000;[可绑定]私有变量_lineWidth:int = 5;覆盖公共函数集数据(值:对象):无效{//能够访问dataGridListData.dataField变量_cellRenderer = (value[dataGridListData.dataField] as CellRendererVO);currentState = _cellRenderer.stateName;}私有函数connectingLinesState_enterStateHandler(event:FlexEvent):void{}受保护的函数 orgChartNodeState_enterStateHandler(event:FlexEvent):void{}]]></fx:脚本><s:State name="emptyState"/><s:State name="orgChartNodeState" enterState="orgChartNodeState_enterStateHandler(event)"/><s:State name="connectingLinesState" enterState="connectingLinesState_enterStateHandler(event)"/></s:states><s:HGroup width="100%" height="100%" includeIn="orgChartNodeState"水平对齐=中心"垂直对齐=中间"></s:HGroup><s:HGroup width="100%" height="100%" includeIn="connectingLinesState"间隙=0"水平对齐=中心"垂直对齐=中间"paddingLeft="0" paddingRight="0" paddingTop="0"paddingBottom="0"></s:HGroup>//示例 spark DataGrid itemRenderer [不工作]包 customComponents.myOrgChart{导入 mx.controls.dataGridClasses.DataGridListData;导入 mx.controls.listClasses.BaseListData;导入 mx.controls.listClasses.IDropInListItemRenderer;导入 mx.controls.listClasses.IListItemRenderer;import spark.components.gridClasses.GridItemRenderer;公共类 TestRenderer 扩展 GridItemRenderer 实现 IListItemRenderer、IDropInListItemRenderer{私有变量 _listData:BaseListData;公共函数 TestRenderer(){极好的();}覆盖公共函数集数据(值:对象):无效{//Flex 在这里抛出错误.//错误:类型错误:错误 #1009:无法访问空对象引用的属性或方法.trace('dataField:' + DataGridListData(listData).dataField);}公共函数获取 listData():BaseListData{返回_listData;}公共函数集 listData(value:BaseListData):void{_listData = 值;}}}谢谢,安吉 解决方案 Spark GridItemRenderer 仍然有一个 data 属性,就像任何其他 ItemRenderer 一样,所以你没问题.除此之外,您还需要 column 属性,返回 GridColumn 实例.这与您在创建 DataGrid 时可能在 mxml 中定义的实例相同,因此它具有其所有属性.您最常用的是 dataField 和 columnIndex.例如:var value:* = data[column.dataField];var index:int = data[column.columnIndex];I am trying to use the same custom renderer for all the columns in a spark DataGrid. I need to know the dataField or columnIndex based on which I can change state in my custom itemrenderer.Earlier in mx:DataGrid, this can be achieved by extending the MXDataGridItemRenderer which implements IDropInListItemRenderer and hence dataGridListData property is available. But using the spark DataGrid, I am extending the GridItemRenderer which DOES NOT implement the IDropInListItemRenderer and hence unable to access dataGridListData property. I have tried to write an action script class extending GridItemRenderer and implementing dataGridListData but flex throws an error in the set function of this variable.Can anyone help me in accomplishing this?// Sample itemRenderer used for mx:DataGrid [Working Code]<fx:Script> <![CDATA[ import mx.events.FlexEvent; import scripts.valueObjects.CellRendererVO; private var _cellRenderer:CellRendererVO = new CellRendererVO(); [Bindable] private var _lineColor:uint = 0xFF0000; [Bindable] private var _lineWidth:int = 5; override public function set data(value:Object):void { //able to access the dataGridListData.dataField variable _cellRenderer = (value[dataGridListData.dataField] as CellRendererVO); currentState = _cellRenderer.stateName; } private function connectingLinesState_enterStateHandler(event:FlexEvent):void { } protected function orgChartNodeState_enterStateHandler(event:FlexEvent):void { } ]]></fx:Script><s:states> <s:State name="emptyState" /> <s:State name="orgChartNodeState" enterState="orgChartNodeState_enterStateHandler(event)"/> <s:State name="connectingLinesState" enterState="connectingLinesState_enterStateHandler(event)"/></s:states><s:HGroup width="100%" height="100%" includeIn="orgChartNodeState" horizontalAlign="center" verticalAlign="middle"></s:HGroup><s:HGroup width="100%" height="100%" includeIn="connectingLinesState" gap="0" horizontalAlign="center" verticalAlign="middle" paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0"></s:HGroup>// sample spark DataGrid itemRenderer [NOT Working]package customComponents.myOrgChart{ import mx.controls.dataGridClasses.DataGridListData; import mx.controls.listClasses.BaseListData; import mx.controls.listClasses.IDropInListItemRenderer; import mx.controls.listClasses.IListItemRenderer;import spark.components.gridClasses.GridItemRenderer;public class TestRenderer extends GridItemRenderer implements IListItemRenderer, IDropInListItemRenderer{ private var _listData:BaseListData; public function TestRenderer() { super(); } override public function set data(value:Object):void { //Flex throws error here. //ERROR: TypeError: Error #1009: Cannot access a property or method of a null object reference. trace('dataField: ' + DataGridListData(listData).dataField); } public function get listData():BaseListData { return _listData; } public function set listData(value:BaseListData):void { _listData = value; }}}Thanks,Anji 解决方案 The Spark GridItemRenderer still has a data property, just as any other ItemRenderer does, so you're fine there.What you need in addition to that is the column property, which returns a GridColumn instance. This is the same instance you probably defined in mxml when creating the DataGrid, hence it has all its properties. The ones you'll use most are dataField and columnIndex.For instance:var value:* = data[column.dataField];var index:int = data[column.columnIndex]; 这篇关于Flex:在自定义 itemrenderer 中获取用于 Spark 数据网格的列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-25 00:48