开发者

Help with containers

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. 开发者_StackOverflow
  3. 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?


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!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜