我创建了一个应用程序,在Flex 3中显示带有自定义列的datagrid
。
如何在此代码中访问方法loadDetails?:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function loadDetails(id:String) : void { // Some code here
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{[{id:'123456',name:'',address:''}]}">
<mx:columns>
<mx:DataGridColumn headerText="Serial" dataField="id"/>
<mx:DataGridColumn headerText="Cliente" dataField="name"/>
<mx:DataGridColumn headerText="Dirección" dataField="address"/>
<mx:DataGridColumn width="50" dataField="id" headerText="">
<mx:itemRenderer>
<mx:Component>
<mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="loadDetails(data.id);">
</mx:LinkButton>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>
当我尝试运行此代码时,Flex会抛出错误。它说没有定义loadDetails。我想这个错误是因为范围。但我对如何解决它一无所知。
答案 0 :(得分:1)
Component标签内的任何内容基本上都是组件工厂的描述符。因此,该标记内的任何内容都将位于本地范围内。但是,您可以使用属性outerDocument(如果我没记错的话)来访问放置itemRenderer的文档。
<mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="outerDocument.loadDetails(data.id);"/>
答案 1 :(得分:0)
或者使用冒泡事件向表单(或其他地方)的听众发出您想要做的事情。