正确的自适应卡输入.ChoiceSet 模板结构

Roy*_*Roy 0 adaptive-cards

数据 json 需要是什么才能设置在 Input.ChoiceSet 上选择的选项?

卡Json

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Input.ChoiceSet",
            "placeholder": "Placeholder text",
            "choices": [
                {
                    "title": "Choice 1",
                    "value": "1"
                },
                {
                    "title": "Choice 2",
                    "value": "2"
                }
            ],
            "style": "expanded",
            "id": "sample"
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0"
}
Run Code Online (Sandbox Code Playgroud)

示例数据 Json

如果我想将 的值设置为 selected ,它的结构应该是什么Choice 1

{
    // I've tried this:
    "sample": {
        "value": "1"
    }
}
-----------------------------
{
    // Also tried
    "sample": "1"
}
Run Code Online (Sandbox Code Playgroud)

我正在阅读Input.ChoiceSet 的自适应卡模式,我发现可以在卡中设置卡 json"value":属性的默认值,但我希望有一种方法可以从模板 json 中执行此操作。否则,在构建卡片之前,我必须将其“注入”到卡片 json 中。

小智 5

根据您的样本,您必须执行以下操作:

            [...]
            "placeholder": "Placeholder text",
            "value": 1,
            "choices": [
                {
                    "title": "Choice 1",
                    "value": "1"
                },
             [...]
Run Code Online (Sandbox Code Playgroud)

根据选择数组中的值之一设置初始值。仅当其中一项的对应值完全相同时,它才有效。如果您想要的话,没有什么像“selected: true”或类似的东西。

当为此使用模板时,您必须返回选定的属性并将其设置为“值”:{$root.selected}