我的數據網格中有2個按鈕列。我想按如下所述實現功能 : 開始時,「比較」按鈕被啓用,並且「發送」按鈕被禁用。點擊比較按鈕後,發送http請求到服務器,只要異步響應返回,使「比較」按鈕被禁用和「發送」按鈕啓用creationComplete事件不會在Itemrenderer中的按鈕中觸發
要實現這一點,我使用內聯的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>
無論如何,你在做什麼都是壞習慣。備份一下,說出你想達到的最終目標是什麼,也許有人可以幫助你完成_that_。 – 2013-02-24 01:31:07
已更新。謝謝。 – user1744585 2013-02-24 02:01:50