2009-08-16 58 views
0

我创建的应用程序,以显示一个datagrid在Flex 3中 自定义列如何访问该方法loadDetails在此代码?:调用从组件外部方法F​​lex 3中

<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没有被定义。我想这个错误是因为范围。但我不知道如何解决这个问题。

回答

1

Component标签内的任何内容基本上都是组件工厂的描述符。因此,该标签内的任何内容都将处于本地范围内。但是,您可以使用属性outerDocument(如果我没有记错的话)访问放置该itemRenderer的文档。

<mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="outerDocument.loadDetails(data.id);"/> 
+0

好的..我学习flex,我现在没有关于.. 我试过了,它的工作原理!! ..谢谢.. =) – l2mt 2009-08-16 19:39:32

0

或者使用冒泡事件的形式,你想做的事(或其他地方)信号上的监听器。