带参数的 AIR 调度事件

发布于 2024-12-13 05:20:50 字数 214 浏览 0 评论 0原文

我有一个带有搜索字段的表单。 当用户按下 Enter 键时,我使用 httpservice 向 mySQL 数据库发送查询。 在某些情况下(很多)有多个记录,因此会打开一个新窗口以使用数据网格显示这些记录,以便用户选择好的结果。

我的问题是如何将选定的信息发送到第一个窗口(带有文本字段)。 我猜调度事件就是这样,但我不知道如何使用!

你能帮我找到解决办法吗?

谢谢

I have a form with a search field.
When user press enter key, I use httpservice to send a query to mySQL database.
In some case (a lot) there are several record, so a new window is opening to show those record with a datagrid to let user chose the good result.

My problem is how to send selected information to the first window (with text field).
I gess that dispatch event is the way but I don't found how to use!

Can you help me to find a solution.

Thanks

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

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

发布评论

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

评论(2

刘备忘录 2024-12-20 05:20:50

如果您尝试在 MDI 环境中进行通信,我建议您使用某种共享模型(也称为中介器或演示模型)来在所需窗口之间保持契约。

class SelectionPM{
     [Bindable]
     public var selectedItem:Object;
}

用例:

Window1 有一个 SelectionPM 实例,当您打开 Window2 时,您会传递
SelectionPM实例到它,然后更新SelectionPM.selectedItem
更改 Window2 数据网格中的选择的属性。那将
将绑定链传播到 Window1,您可以在其中使用
SelectionPM.selectedItem 如您所愿。

理想情况下,您会使用 IoC 容器进行模型注入,但那是另一回事了。

这可能看起来工作量很大,但如果您在应用程序中保留这种方法,您将从中受益。

干杯!

If you are trying to communicate within an MDI environment I suggest that you use some kind of shared model ( aka Mediator or Presentation Model ) that keeps a contract between the desired windows.

class SelectionPM{
     [Bindable]
     public var selectedItem:Object;
}

Use case:

Window1 has an instance of SelectionPM, when you open Window2 you pass
SelectionPM instance to it, then update SelectionPM.selectedItem
property on changing selection in the Window2 datagrid. That will
propagate the binding chain up to Window1, where you can use the
SelectionPM.selectedItem as you wish.

Ideally you would use an IoC container for model injection but that is another story.

That might seem like a lot of work but if you keep this methodology across your app you will benefit from it.

Cheers!

空宴 2024-12-20 05:20:50

这是一组四个类作为基础。显然您不想在构造函数中进行如下实际工作。

public class App
{
    public static var eventDispatcher:EventDispatcher = new EventDispatcher();
    public function App()
    {
        new Window1();
    }
}

class AppEvent extends Event
{
    public static const DATA_READY:String = "APPEVENT.DATA_READY";
    public var data:Object;
    public function AppEvent( type:String, data:Object )
    {
        super( type );
        this.data = data;
    }
}

class Window1
{
    public function Window1()
    {
        App.eventDispatcher.addEventListener( AppEvent.DATA_READY, onDataReady );
        ...DO STUFF...
        new Window2();
    }
    private function onDataReady( evt:AppEvent ) : void
    {
        ...DO STUFF WITH "evt.data"....
    }
}

class Window2
{
    public function Window2()
    {
        ...GET DATA FROM SERVER AND PUT IT IN "data"...
        App.eventDispatcher.dispatchEvent( new AppEvent( AppEvent.DATA_READY, data ) );
    }
}
</pre>

Here's a set of four classes as a basis. Obviously you don't want to be doing the actual work in the constructors as below.

public class App
{
    public static var eventDispatcher:EventDispatcher = new EventDispatcher();
    public function App()
    {
        new Window1();
    }
}

class AppEvent extends Event
{
    public static const DATA_READY:String = "APPEVENT.DATA_READY";
    public var data:Object;
    public function AppEvent( type:String, data:Object )
    {
        super( type );
        this.data = data;
    }
}

class Window1
{
    public function Window1()
    {
        App.eventDispatcher.addEventListener( AppEvent.DATA_READY, onDataReady );
        ...DO STUFF...
        new Window2();
    }
    private function onDataReady( evt:AppEvent ) : void
    {
        ...DO STUFF WITH "evt.data"....
    }
}

class Window2
{
    public function Window2()
    {
        ...GET DATA FROM SERVER AND PUT IT IN "data"...
        App.eventDispatcher.dispatchEvent( new AppEvent( AppEvent.DATA_READY, data ) );
    }
}
</pre>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文