0

我创建了一个应用程序来显示datagridFlex 3 中的自定义列。如何访问此代码中的方法 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 没有定义。我想这个错误是因为范围。但我不知道如何解决它。

4

2 回答 2

1

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

<mx:LinkButton label="" toolTip="Details" icon="@Embed('../resources/icons/details.png')" click="outerDocument.loadDetails(data.id);"/>
于 2009-08-16T19:30:35.093 回答
0

或者使用冒泡事件向表单(或其他地方)上的侦听器发出您想要做什么的信号。

于 2013-07-11T19:29:35.707 回答