问题描述
我想根据其值更改来自数据库的自适应卡输出的颜色,例如:如果 workhour
知道我必须如何实现这一目标吗?
下面是 JSON 代码的一部分以及我从数据库调用的数据。 此外,我将在 Microsoft Teams 上实施此功能。
"type": "Column","items": [
{
"type": "TextBlock","weight": "bolder","text": "Work Hours"
},{
"$data": "${AttendanceMonthly}","type": "TextBlock","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}"
}]
根据您的数据,这将使 workHours 低于 6 的文本变为红色。请记住,您只能将颜色设置为“注意”、“良好”等,而不能直接设置颜色代码。