このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、
お気軽にご連絡ください。
App Builder is not supported for your selected
Datadog site (
).
If you want to encapsulate logic within your app, you can use state variables.
Create a state variable
To add a state variable to your app, perform the following steps:
- In your app, click {𝑥} to open the Variables tab.
- Click Create Variable.
- Optionally, click the variable name and rename it.
- Define the initial value for your state variable.
Example app
To create an app that uses a button to change a callout value component’s style and value, follow these instructions.
Create the variables
- In your app, click {𝑥} to open the Variables tab.
- Click Create Variable.
- Name the variable
callout_value
and set its Initial Value to Pass
. - Click the + (plus) to create another variable.
- Name this variable
callout_color
and set its Initial Value to green
.
Create the components
- Add a callout value component to your app. Give it the following values:
- Value:
${callout_value.value}
- Style:
${callout_color.value}
- Add a button component to your app and set its label to
Change status
. - Under Events, add an event. Give it the following values:
- Event:
click
- Reaction:
custom
- Callback:
${ () => {
if(callout_color.value !== "green"){
callout_color.setValue("green")
callout_value.setValue("Pass")
} else {
callout_color.setValue("red")
callout_value.setValue("Fail")
}
} }
- Click Preview to preview your app.
When you click the Change status button in your app, the color and text of the callout value element alternate between a green Pass and a red Fail.
Further reading
Do you have questions or feedback? Join the #app-builder channel on the Datadog Community Slack.