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

6 ビュー (過去 30 日間)
Delaney
Delaney 2022 年 9 月 9 日
回答済み: Walter Roberson 2022 年 9 月 9 日
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 Center および File ExchangeDevelop 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