我的Flex
- 应用程序出了问题。正如您在下面的代码示例中所看到的,我尝试将一些面板添加到vgroup。这些小组从MYSQL
db获得了他们的头衔。我的问题是我不能等待callresponder
的异步调用,因此面板不会被填充。我怎样才能等待来自DB的数据?
如果我尝试使用按钮构建一个新面板,它可以工作。当我按下按钮时,会出现一个带有正确标题的面板。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
xmlns:produktservice="services.produktservice.*"
xmlns:valueObjects="valueObjects.*">
<fx:Script>
<![CDATA[
import mx.containers.Panel;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private var zaehler:int = 0;
private function getProduktByID(i:int):void
{
getProduktByIDResult.token = produktService.getProduktByID(i);
}
private function init():void
{
for(var i:int=0; i<10; i++)
{
getProduktByID(818+i);
}
}
protected function getProduktByIDResult_resultHandler(event:ResultEvent):void
{
var dynamicPanel:Panel;
dynamicPanel = new Panel();
dynamicPanel.id="dynamicPanel"+zaehler;
dynamicPanel.width=400;
dynamicPanel.height=200;
dynamicPanel.title=getProduktByIDResult.lastResult.titel;
vPanelGroup.addElement(dynamicPanel);
}
protected function button1_clickHandler(event:MouseEvent):void
{
getProduktByID(818+zaehler);
zaehler++;
}
]]>
</fx:Script>
<fx:Declarations>
<produktservice:ProduktService id="produktService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="getProduktByIDResult" result="getProduktByIDResult_resultHandler(event)"/>
<valueObjects:Produkt id="produkt"/>
<!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
</fx:Declarations>
<s:VGroup id="vPanelGroup" gap="10" creationComplete="init()">
</s:VGroup>
<s:Button x="726" y="270" label="Button" click="button1_clickHandler(event)"/>
</s:Application>
答案 0 :(得分:0)
是吗
protected function getProduktByIDResult_resultHandler(event:ResultEvent):void
{
var dynamicPanel:Panel;
dynamicPanel = new Panel();
dynamicPanel.id="dynamicPanel"+zaehler;
dynamicPanel.width=400;
dynamicPanel.height=200;
dynamicPanel.title=event.result.titel;
vPanelGroup.addElement(dynamicPanel);
}