自适应卡片根据 if 条件更改文本颜色
Adaptive Cards change text color from if condition
我想根据其值更改来自数据库的自适应卡输出的颜色,例如:如果工作时间 < 6 = 显示工作时间的自适应卡的颜色必须为红色。如果超过 6 小时,工作时间必须显示为绿色。
知道我必须如何实现这一点吗?
下面是 JSON 代码的一部分以及我从数据库调用的数据。
此外,我将在 Microsoft Teams 上实现它。
"type": "Column",
"items": [
{
"type": "TextBlock",
"weight": "bolder",
"text": "Work Hours"
},
{
"$data": "${AttendanceMonthly}",
"type": "TextBlock",
"weight": "bolder",
"separator": true,
"text": "${WorkedHours}"
}
你可以用if设置颜色为attention或good。
看这个例子:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"$data": "${AttendanceMonthly}",
"type": "TextBlock",
"weight": "bolder",
"separator": true,
"color": "${if(WorkedHours < 6, 'attention', 'good')}",
"text": "Hours worked: ${WorkedHours}"
}]
根据您的数据,这会使低于 6 的工作时间的文本变为红色。请记住,您只能将颜色设置为“注意”、“良好”等,而不能直接设置颜色代码。
我想根据其值更改来自数据库的自适应卡输出的颜色,例如:如果工作时间 < 6 = 显示工作时间的自适应卡的颜色必须为红色。如果超过 6 小时,工作时间必须显示为绿色。
知道我必须如何实现这一点吗?
下面是 JSON 代码的一部分以及我从数据库调用的数据。 此外,我将在 Microsoft Teams 上实现它。
"type": "Column",
"items": [
{
"type": "TextBlock",
"weight": "bolder",
"text": "Work Hours"
},
{
"$data": "${AttendanceMonthly}",
"type": "TextBlock",
"weight": "bolder",
"separator": true,
"text": "${WorkedHours}"
}
你可以用if设置颜色为attention或good。 看这个例子:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"$data": "${AttendanceMonthly}",
"type": "TextBlock",
"weight": "bolder",
"separator": true,
"color": "${if(WorkedHours < 6, 'attention', 'good')}",
"text": "Hours worked: ${WorkedHours}"
}]
根据您的数据,这会使低于 6 的工作时间的文本变为红色。请记住,您只能将颜色设置为“注意”、“良好”等,而不能直接设置颜色代码。