Itemrenderer中的Button中不会触发creationComplete事件

时间:2013-02-24 01:25:59

标签: actionscript-3 flex actionscript

我的数据网格中有2个按钮列。我想要实现这个功能 如下所述: 开始时,“比较”按钮启用,“发送”按钮被禁用。单击“比较”按钮后,向服务器发送http请求,一旦返回异步响应,禁用“比较”按钮并启用“发送”按钮

为了实现这一点,我使用内联Itemrenderer作为按钮列。 “发送”和“按钮”有2个按钮。在每行数据网格中“比较”,如下所示。

要在应用程序级别设置按钮状态,我定义了2个对象(map)以将按钮存储在datagrid中。

//for storing send buttons.the key is the first hidden column value "id". 
[Bindable]
public var sendButtonMap:Object = new Object();

//for storing compare buttons.the key is the same as above.
[Bindable]
public var compareButtonMap:Object = new Object();

当按钮初始化时,我将按钮注册到地图,以便我可以控制itenrenderer外面的按钮。

<mx:Button label="Compare" creationComplete="compareBtn_creationCompleteHandler(event)" />

问题是在初始化页面时不会触发creationComplete。 我在itemrenderer之外制作了按钮,效果很好。 为什么没有触发creationComplete事件? 这里列出了mxml

<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" 
          xmlns:s="library://ns.adobe.com/flex/spark" 
          xmlns:mx="library://ns.adobe.com/flex/mx"
          xmlns:configurationIngestSource="configuration.ingestSource.*"
          xmlns:commonComponent="common.*"
          paddingLeft="5"
          paddingTop="5"
          creationComplete="sourceDeviceList_creationCompleteHandler(event);ingestSourceMain_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            [Bindable]
            public var sendButtonMap:Object = new Object();
            //Alert.show("init sendButtonMap");
            [Bindable]
            public var compareButtonMap:Object = new Object();
        ]]>
    </fx:Script>
<s:DataGrid id="sourceDeviceDataGrid"
            width="{Util.getMainNavigatorWidth() - 27}" 
            height="{Util.getMainNavigatorHeight() / 3 * 2 }"
            selectionMode="singleRow"
            doubleClickEnabled="true"
            dataProvider="{localSourceDevices}">                                
    <s:columns>
        <s:ArrayList>
            <s:GridColumn dataField="id" 
                          headerText="id"
                          visible="false"
                          headerRenderer="{customHeaderRenderer}"/>
            <s:GridColumn dataField="name" 
                          headerText="Name"
                          width="{Util.getMainNavigatorWidth() / 6 }"
                          headerRenderer="{customHeaderRenderer}"/>

            <s:GridColumn dataField="id" 
                          headerText="Compare"
                          width="{Util.getMainNavigatorWidth() / 6 }"
                          headerRenderer="{customHeaderRenderer}">
                <s:itemRenderer>
                    <fx:Component>
                        <s:GridItemRenderer creationComplete="compareBtn_creationCompleteHandler(event)" >                                  
                            <fx:Script>
                                <![CDATA[
                                    import spark.components.Button;
                                    import mx.events.FlexEvent;
                                    import mx.controls.Alert;

                                    protected function compareBtn_creationCompleteHandler(event:FlexEvent):void
                                    {
                                        //Never reach here,anything wrong?
                                        Alert.show(this.data.id);
                                        outerDocument.compareButtonMap[this.data.id] = event.target;
                                    }   

                                ]]>
                            </fx:Script>
                            <mx:Button label="Compare" creationComplete="compareBtn_creationCompleteHandler(event)" />
                        </s:GridItemRenderer>
                    </fx:Component>
                </s:itemRenderer>

            </s:GridColumn>
            <s:GridColumn dataField="id" 
                          headerText="Send"
                          width="{Util.getMainNavigatorWidth() / 6 }"
                          headerRenderer="{customHeaderRenderer}">
                <s:itemRenderer>
                    <fx:Component>
                        <s:GridItemRenderer>                                        
                            <fx:Script>
                                <![CDATA[

                                    import mx.events.FlexEvent;
                                    import mx.controls.Alert;

                                    protected function sendBtn_creationCompleteHandler(event:FlexEvent):void
                                    {

                                        import mx.utils.ObjectUtil;
                                        outerDocument.sendButtonMap[this.data.id] = event.currentTarget;
                                        Alert.show( ObjectUtil.toString(event.currentTarget));
                                    }                                                                                                                                       
                                ]]>
                            </fx:Script>
                            <mx:Button label="Send" creationComplete="sendBtn_creationCompleteHandler(event)" />


            </s:GridItemRenderer>
                    </fx:Component>
                </s:itemRenderer>

            </s:GridColumn>
        </s:ArrayList>
    </s:columns>            
</s:DataGrid>
</s:VGroup>

1 个答案:

答案 0 :(得分:1)

将可绑定isCompared属性添加到localSourceDevices中存储的任何类型的对象。将发送按钮的enabled绑定到isCompared,将比较按钮的enabled绑定到!isCompared。请求进入时,请将该变量的值从false更改为true