What is he doing "@"?

Sometimes I see the following in a project I'm working on:

text="@{myVar}" 

What does this @ do?

Edit: text is a property, for example, in the TextArea component.

+6
source share
1 answer

The @ symbol is used for two-way binding. Traditional binding is only one way. So you have something similar in ActionScript:

 [Bindable] public var myValue:String = 'test'; 

And this is in MXML

 <s:TextInput id="myInput" text="{myValue}" /> 

myValue is the source, and the text property in myInput is the destination.

When the myValue variable changes, the text TextInput property changes. However, if you enter myInput; the value of myValue will not change.

This is one way binding. Changing the source (myValue) changes the destination (myInput.text), but changing the destination (myInput.text) does not change the source (myValue).

When you add '@', it creates a two-way binding:

  <s:TextInput id="myInput" text="@{myValue}" /> 

So now that myValue is changing, the TextInput text property will change. (As in the previous example). Whenever myInput.text changes, myValue also changes (unlike the previous sample).

"@" basically makes both values ​​(myValue and myInput.text) the source and destination for the binding.

You can accomplish the same thing without the "@" using the Binding tag:

 <fx:Binding source="myInput.text" destination="myValue " /> 

Is this a more detailed explanation for you?

+23
source

Source: https://habr.com/ru/post/901652/


All Articles