Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the skills of Flex data binding

Shulou Source: shulou.com Published: 2022-06-02 08:04:25 09月22日 Update

This article mainly introduces Flex data binding skills, the article is very detailed, has a certain reference value, interested friends must read it!

Flex data binding skills

There is an easy way to activate / disable controls by selecting them. For example, suppose you have a DataGrid and buttons that manipulate data, some of which can only be used when a row is selected, others can only be used when unselected, and some can only be used when a specific row is selected.

problem

To do this, you may need to write some if statements or use Flex data binding to set a variable and then constantly adjust the value of the variable in the code. It's like this:

Program code

[Bindable] privatevarsomethingSelected:Boolean=false

That's a good idea. All controls that depend on the selected state of DataGrid are bound to a variable. Changing this variable changes the active state of the control. However, you still need to decide when to change this variable. For example:

Program code

PrivatefunctionpublishItem (): void {/ / gettheselecteditem / / publishit grid.selectedItem=-1;//cleartheselection somethingSelected=false;}

Let's complicate things a little bit, assuming that the selected row contains a special value and a button will be activated. Now you need to pay attention not only to the variable somethingSelected, but also to this additional check. In other words, you need to set another variable in the publishItem () function. The more conditions there are, the more complex the function will be.

A simpler method

Here is a simpler way to do this. Now that the button is bound to the somethingSelected variable, all that's left is to bind the somethingSelected variable to the state of DataGrid. You can use the tag:

Program code

Now the value of somethingSelected is bound to the selected state of DataGrid. Selecting a row of somethingSelected changes to true, then all tags with enabled= "{somethingSelected}" will be activated, and buttons with enabled= "{! somethingSelected}" in all tags will be disabled.

The source of the ◆ Bingding tag does not have to be a variable. It can be an expression, as shown below. Here source is a simple condition to determine whether the selectedIndex of DataGrid is greater than or equal to 0.

Here is a slightly more complicated example:

Program code

A value of 1 for a field of a record in DataGrid will change the value of the variable codeOnePicked to true.

Program code

Here, as long as the selected record code field in DataGrid is 1, the Magi CheckBox is selected and the button is disabled.

These are all the contents of the article "what are the Flex data binding techniques?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Variables buttons code data labels programs times states techniques complexity controls methods activation one line examples content functions that is conditions articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL vpn Huawei macOS