0

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

为了实现这一点,我将内联 Itemrenderer 用于按钮列。数据网格的每一行都有“发送”和“比较”两个按钮,如下图所示。

为了在应用程序级别设置按钮状态,我定义了 2 个对象(地图)来将按钮存储在数据网格中。

//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>
4

1 回答 1

1

将 BindableisCompared属性添加到存储在localSourceDevices. 将 Send 按钮的enabledtoisCompared和 Compare 按钮的enabledto绑定!isCompared。当请求进来时,将该变量的值从 更改falsetrue

于 2013-02-24T02:13:26.467 回答