容器帮助

发布于 2024-11-01 21:44:44 字数 436 浏览 0 评论 0原文

我正在使用视图堆栈...所以当视图更改时,例如我们从一个页面移动到另一个页面时,会调度隐藏事件。所以我在进入下一页之前保存隐藏事件中最后一页的信息。但问题是,如果我没有改变任何东西仍然改变视图隐藏事件被调用并调用转到后端...我只想仅当视图中的总和发生变化时才调用..就像总文本值...所以我有两个选项

  1. 使用事件每个组件上的侦听器,如果总和发生变化,则使标志为 true...并隐藏事件检查,如果标志为 true,则发送调用到后端。

  2. 容器级别的事件侦听器..如果子组件中的 sumthing 通过冒泡容器发生更改知道是否调度了 sum 事件。nd 使标志为 true。

我对容器有疑问...

  • 我可以使用容器吗?如何使用?
  • 为什么我不能使用容器?
  • 这两种方式有什么优点和缺点?

I am using view stack...so when view change like when we move from one page to another hide event is dispatched.So i am saving the information of last page in hide event before i go to next page.but thing is that if i change nothing still change on view hide event is invoked nd call go to backend...i just want do call only if sumthing change in the view..like sum text value...So i have two options

  1. use event listener on each component if sumthing change its make the flag true...nd hide event check, if flag is true send call to backend.

  2. event listener at container level ..if sumthing change in child componenet through bubbling container knows if sum event is dispatched.nd makes the flag true.

I have doubt with container...

  • Can i use container, and how?
  • Reason why I can't use container?
  • What are the pros and cons either way?

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

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

发布评论

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

评论(3

小帐篷 2024-11-08 21:44:44

我建议使用能够比较它们的 dataProvider。例如,如果您要使用文本输入更改内容,您基本上可以执行如下操作:

[Bindable]
private var myDataProvider:Object = new Object();

private function creationCompleteHandler():void {
  myDataProvider.updated = false;
  myDataProvider.defaultValue = 'default';
  myDataProvider.defaultValueTwo = 'default';
}

等等。

然后,在您的 mxml 中,您可以执行如下操作:

<mx:TextInput id="myText" text="{myDataProvider.defaultValue}" change="myDataProvider.defaultValue=myText.text; myDataProvider.updated=true;" />

最后,在您的 hide 事件中,您可以执行以下操作:

private function hideEventHandler( event:Event ):void {
  if( myDataProvider.updated ){
    // Call your RemoteServices (or w/e) to update the information
  }
}

这样,当发生任何变化时,您可以更新您的 dataProvider 并每次都可以访问新信息。

希望这有帮助!

I would recommend using a dataProvider with the ability to compare them. For instance, if you are changing things with textinputs, you could basically do something like this:

[Bindable]
private var myDataProvider:Object = new Object();

private function creationCompleteHandler():void {
  myDataProvider.updated = false;
  myDataProvider.defaultValue = 'default';
  myDataProvider.defaultValueTwo = 'default';
}

etc.

Then, in your mxml, you can have something like this:

<mx:TextInput id="myText" text="{myDataProvider.defaultValue}" change="myDataProvider.defaultValue=myText.text; myDataProvider.updated=true;" />

Lastly, in your hide event, you can do the following:

private function hideEventHandler( event:Event ):void {
  if( myDataProvider.updated ){
    // Call your RemoteServices (or w/e) to update the information
  }
}

This way, when anything changes, you can update your dataProvider and have access to the new information each time.

Hope this helps!

江挽川 2024-11-08 21:44:44

我在过去的几个项目中使用了与您的第一个选项类似的方法。在每个表单控件的 change 事件中,我调用一个小函数,该函数仅将模型中的 changesMade 标志设置为 true 。当用户尝试离开我的表单时,我会检查 changesMade 标志以查看是否需要保存信息。

I've used an approach similar to your first option in a couple of my past projects. In the change event for each of my form's controls I make a call to a small function that just sets a changesMade flag to true in my model. When the user tries to navigate away from my form, I check the changesMade flag to see if I need to save the info.

当爱已成负担 2024-11-08 21:44:44

数据模型是你的朋友!

如果您养成了从加载的数据中创建强类型数据模型的习惯,那么这样的问题就会变得非常基本。

我总是有一个键绑定集来生成与此类似的代码片段...

    private var _foo:String;

    public function get foo():String
    {
        return _foo;
    }

public function set foo(value:String):void
{
    if(_foo == value)
        return;

    var oldVal:String = _foo;
    _foo = value;

    this.invalidateProperty("foo", oldVal, value);
}

如果您的数据使用这样的 getters/setters,那么验证模型级别的更改将非常容易,从而将视图完全从过程中删除。

Data models are your friend!

If you get in the habit of creating strongly typed data models out of your loaded data, questions like this become very basic.

I always have a key binding set to generate a code snipit similar to this...

    private var _foo:String;

    public function get foo():String
    {
        return _foo;
    }

public function set foo(value:String):void
{
    if(_foo == value)
        return;

    var oldVal:String = _foo;
    _foo = value;

    this.invalidateProperty("foo", oldVal, value);
}

If your data used getters/setters like this, it would be very easy to validate a change on the model level, cutting the view out of the process entirely.

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