呼叫响应者的异步调用

发布于 2024-12-11 10:18:22 字数 2577 浏览 0 评论 0原文

我的 Flex 应用程序有问题。正如您在下面的代码示例中看到的,我尝试向 vgroup 添加一些面板。这些面板从我的 MYSQL 数据库获取标题。我的问题是我无法等待 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>

I have a problem with my Flex-Application. As you can see in the code-sample below i try to add some panels to a vgroup. The panels are getting their title from my MYSQL db. My problem is that I can't wait on the async call of the callresponder, so the panel doesn't get filled. How can I wait for the data from DB?

If i try to build a new panel with a button it works. When i press the button one panel appears with the right title.

 <?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赏烟花じ飞满天 2024-12-18 10:18:22

是吗

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);
}

Is it

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);
}

?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文