Zmienne kontekstowe umożliwiają tworzenie komponentów zbudowanych w sposób funkcyjny. Twórca komponentu może zdefiniować wiele dowolnych zmiennych kontekstowych, które będą mogły być następnie wykorzystane przez użytkownika w funkcjach zdefiniowanych jako parametry tego komponentu.
Przykładem takiego komponentu może być walidator, który pozwala na walidację danych w tabelce dynamicznej. Udostępniana jest wtedy zmienna kontekstowa Tak skonfigurowana akcja będzie oznaczała, że funkcja
Pozwala to na tworzenie bardziej uniwersalnych komponentów. Nie musimy też tworzyć wielu przeciążeń funkcji np. dla parametrów tablicowych — wystarczy wykorzystać komponent, który umożliwi iterację po wierszach takich tablic. Definiowanie zmiennych kontekstowychDefiniowanie zmiennych kontekstowych (
Ustalenie wartości zmiennych kontekstowychWartość zmiennych kontekstowych ustawia się przy użyciu obiektu
Zmienne kontekstowe w akcjach formularzaZe względu na inne środowisko uruchamiania akcji formularza, sposób ustawiania tych zmiennych jest trochę inny. Wartość kontekstowych zmiennych ustawiamy przy użyciu metody
|
Context variables allow the creation of components built in a functional way. The creator of a component can define many arbitrary context variables, which can then be used by the user in functions defined as parameters of that component.
An example of such a component could be a validator, which allows you to validate data in a dynamic table. A context variable $currentRow is then provided, storing the index of the current row in the table. The only parameter would be a function that would return a logical value saying whether the row is valid or not The action configured this way will mean that the
This allows us to create more versatile components. Also, we don't need to create multiple function overloads, for example, for array parameters - it's enough to use a component that allows iteration over rows of such arrays. Defining context variablesDefining context variables (
Determine the value of context variablesThe value of context variables is set using an object parameter to the component method (e.g. and use the
Context variables in form actionsDue to the different environment of running form actions, the way of setting these variables is a little different. We set the value of context variables using the
|