将具有动态长度的阵列绑定到自适应卡

时间:2020-09-04 09:58:05

标签: c# botframework adaptive-cards

我想知道如何将具有动态长度的数组绑定到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"
]
}

Card

1 个答案:

答案 0 :(得分:2)

最好的方法是将JSON修改一下:

error: unknown parameter name

通过这种方式,您可以像这样构建卡:

{
"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"
    }

]
}

看起来像这样:

enter image description here