如何在自定义itemrenderer中访问/传递值对象?项呈示器表示我的数据网格中的一个字段,我希望能够访问我的VO中的属性。
由于
答案 0 :(得分:1)
您需要覆盖项呈示器的设置数据方法:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo">
<fx:Script>
<![CDATA[
//Strongly typed VO for use in binding.
[Bindable]
private var myValueObject:MyValueObject;
override public function set data(value:Object) : void
{
//we don't want to update if the value is the exact same.
if(data === value)
return;
//you could simply access the data property but I think
//it is nicer to have strong typing for code hints
super.data = myValueObject = value;
validateNow();
}
]]>
</fx:Script>
<mx:Label text="{myValueObject.name}"/>
</mx:Canvas>
答案 1 :(得分:0)
这种方法怎么样?
项目渲染器ItemRendererLink.mxml:
public function goTo():void {
Alert.show(goToScreen + " " + data.item_num);
}
]]>
</mx:Script>
</mx:LinkButton>
父组件:
<mx:DataGridColumn dataField="item_num"
headerText="Item #">
<mx:itemRenderer>
<mx:Component>
<e:ItemRendererLink goToScreen="item"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>