【问题标题】:Bind an Array with dynamic length to an Adaptive Card将具有动态长度的数组绑定到自适应卡
【发布时间】:2020-12-23 14:14:19
【问题描述】:

我想知道如何将可以具有动态长度的数组绑定到 Microsoft 自适应卡中的元素。具体来说,我想制作一个带有说明的列表,并以动态布局在“列表类型”中显示这些说明。在一个完美的世界中,这个列表将被动态填充并将其长度调整为数组的长度。有什么想法/解决方法吗?

卡片负载:

{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
    {
        "type": "TextBlock",
        "text": "${title}",
        "size": "Medium",
        "weight": "Bolder",
        "wrap": true,
        "separator": true
    },
    {
        "type": "FactSet",
        "facts": [
            {
                "title": "1.",
                "value": "${instructions[1]}"
            },
            {
                "title": "2.",
                "value": "${instructions[2]}"
            },
            {
                "title": "3.",
                "value": "${instructions[3]}"
            },
            {
                "title": "4.",
                "value": "${instructions[4]}"
            },
            {
                "title": "5.",
                "value": "${instructions[5]}"
            }
        ],
        "isVisible": false,
        "$data": "${$root['instructions[0]']}",
        "separator": true
    }
]
}

卡片数据:

{
"title": "Instructions:",
"instructions" : [
    "blablablba",
    "qwerertzasdfadfds fasdf ",
    "asdfkjhasf 3 asdflkjw",
    "Lorem ipsum dolor mi",
    "hello world",
    "last instruction"
]
}

【问题讨论】:

    标签: c# botframework adaptive-cards


    【解决方案1】:

    最好的方法是稍微更改一下 JSON:

    {
    "title": "Instructions:",
    "instructions": [{
            "id": "1",
            "text": "blablablabla"
        },
        {
            "id": "2",
            "text": "qwerertzasdfadfds fasdf "
        },
        {
            "id": "2",
            "text": "asdfkjhasf 3 asdflkjw"
        },
        {
            "id": "3",
            "text": "Lorem ipsum dolor mi"
        },
        {
            "id": "4",
            "text": "hello world"
        },
        {
            "id": "5",
            "text": "last instruction"
        }
    
    ]
    }
    

    这样你可以像这样构建卡片:

    {
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.3",
    "body": [
        {
            "type": "TextBlock",
            "text": "${title}",
            "size": "Medium",
            "weight": "Bolder",
            "wrap": true,
            "separator": true
        },
        {
            "type": "FactSet",
            "facts": [
                {
                    "$data": "${instructions}",
                    "title": "${id}.",
                    "value": "${text}"
                }
            ],
            "separator": true
        }
    ]
    }
    

    看起来像这样:

    【讨论】:

      猜你喜欢
      • 2020-05-13
      • 1970-01-01
      • 2020-12-21
      • 2022-07-25
      • 2019-08-26
      • 1970-01-01
      • 2018-08-03
      • 2017-09-28
      • 1970-01-01
      相关资源
      最近更新 更多