App Designer: Using app.Component.Value vs. event.Value in callback function

10 visualizaciones (últimos 30 días)
I am writing a callback function in App Designer where the user has selected an option from a drop-down menu. It seems to me that there are two ways to obtain the value that the user has selected.
Let us say that I have a callback function
function DropDownValueChanged(app, event)
that refers to my UI component DropDown. It seems to me that there are two ways to get the value that was selected from the drop-down menu. According to the section "Callback Input Argments" of this help page, the options are:
value = event.Value;
or
value = app.DropDown.Value;
Is there any tradeoff between using these two approaches? Why even pass event as an argument to the callback function if the same data is stored in app.Component?

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Sept. de 2022
You can code the exact same callback for multiple components. You would not know immediately which component the event was for. It might not even have a particular name: it might be part of an array of objects. Using the event information gets you what you need immediately.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by