json 自适应卡内的多个 if-else

Multiple if-else within json adaptive card

0

我不熟悉自适应卡片以及自适应卡片上 JSON 条件语句的用法。

我能知道是否可以使用多个 if-else 语句更改自适应卡片文本的颜色吗?比如有3种颜色输出选项。

此外,自适应卡 1.0 版是否支持 if-else 语句?

下面是我之前通过提问从这里找到的代码示例,但是适配卡的版本是否会通过在颜色中给出if条件来影响输出?

{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"body": [
    {            
          "$data": "${AttendanceMonthly}",
          "type": "TextBlock",
          "weight": "bolder",
          "separator": true,
           "color": "${if(WorkedHours < 6, 'attention', 'good')}",
          "text": "Hours worked: ${WorkedHours}"
    }]

您可以嵌套 if/else 语句,例如:

${if(WorkedHours < 6, 'attention', if(<condition>, <true>, <false>))}"

但是,根据您要实现的目标,您可能会从使用其他一些 logical operators 中获益更多。

我不记得哪个版本开始支持 Adaptive Expression Language, but you may as well set to version 1.3, if you can. Note, however, that if you're using cards you created before May 2020, there might be some breaking changes in data binding