问题描述
我想使用相同的自定义渲染器中的所有列在火花的DataGrid
。我需要知道的dataField
或参数:columnIndex
在此基础上,我可以改变状态
在我的定义ItemRenderer。
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.
在MX早些时候:DataGrid中,这可以通过扩展实现了 MXDataGridItemRenderer
它实现 IDropInListItemRenderer
,因此 dataGridListData code>属性可用。
Earlier in mx:DataGrid, this can be achieved by extending the MXDataGridItemRenderer
which implements IDropInListItemRenderer
and hence dataGridListData
property is available.
但是用火花的DataGrid,我延长了 GridItemRenderer
不落实 IDropInListItemRenderer
,因此无法访问 dataGridListData code>属性。我试图写一个扩展
GridItemRenderer
和执行动作脚本类 dataGridListData code>,但弯曲的<$ C抛出一个错误$ C>设置
函数这个变量。
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.
谁能帮我完成这个?
//样品的itemRenderer MX:DataGrid的 [工作code]
// 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>
//样的火花的DataGrid的itemRenderer [不工作]
// sample spark DataGrid itemRenderer [NOT Working]
包customComponents.myOrgChart{ 进口mx.controls.dataGridClasses.DataGridListData; 进口mx.controls.listClasses.BaseListData; 进口mx.controls.listClasses.IDropInListItemRenderer; 进口mx.controls.listClasses.IListItemRenderer;
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;
}
}
}
谢谢
安吉
推荐答案
星火GridItemRenderer仍然有一个数据
属性,就像任何其他的ItemRenderer做,所以你精细那里。
The Spark GridItemRenderer still has a data
property, just as any other ItemRenderer does, so you're fine there.
您需要另外的什么是 属性栏,它返回一个的GridColumn 实例。这是在MXML中创建数据网格时,你可能定义相同的实例,因此它有它的所有属性。你会用最大的是的dataField 和参数:columnIndex 。
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.
例如:
var value:* = data[column.dataField];
var index:int = data[column.columnIndex];
这篇关于软硬度:获得列索引定义ItemRenderer火花数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!