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

6 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2022-9-9
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by