Inconvenient way to reset data in 2-way-binding : Flex 4.1
We all love the inconvience of 2 ways binding. But how to eas开发者_高级运维ily reset the affected data in case of pressing cancel button.
I have cruised all over the internet (mostly :D ) for the answer but all the sample I saw don't have that reset button in the form o_0.
If you have any idea, please help.
Thanks
I consider 2 way data binding to be very convenient in many cases
If you want to reset a value to the old value; you'll you have to store a copy of that old value. There are plenty of ways to do this. One is to do a "Copy" of the data before your input is populated. In the reset click handler; just copy the stored values back into the input values of your form.
Another way could be to listen for the 'focusIn' event on the component in question. For example, if you are bidning to the text property of a TextInput, you might do something like this:
<s:TextInput id="textInput" focusIn="onFocusIn()"/>
In the onFocusIn event handler, store the old value you want to store in some public variable:
oldTextInputText = textInput.text;
In your reset handler; just swap the values:
textInput.text = oldTextInputText;
精彩评论