2

Slack 让您可以使用块工具包构建器非常轻松地构建 UI,包括添加复选框:如何使所有复选框默认选中(使用 JS)?当用户打开应用程序主页时,是否有甚至选择 1 个复选框?如果我能做一个,其余的应该很容易。

{
"type": "home",
"blocks": [
    {
    "type": "input",
    "element": {
        "type": "checkboxes",
        "options": [
            {
                "text": {
                    "type": "plain_text",
                    "text": "*this is plain_text text*",
                    "emoji": true
                },
                "value": "value-0"
            },
            {
                "text": {
                    "type": "plain_text",
                    "text": "*this is plain_text text*",
                    "emoji": true
                    },
                  "value": "value-1"
              }
          ],
          "action_id": "checkboxes-action"
      },
      "label": {
          "type": "plain_text",
          "text": "Label",
          "emoji": true
      }
  }
]
}
4

1 回答 1

3

您需要initial_options在块套件代码中使用字段。
https://api.slack.com/reference/block-kit/block-elements#checkboxes__fields

initial_options

与选项中的一个或多个选项完全匹配的选项对象数组。这些选项将在复选框组最初加载时被选中。

样本

"initial_options": [
                {
                    "text": {
                        "type": "plain_text",
                        "text": "*this is plain_text text*",
                        "emoji": true
                    },
                    "value": "value-0"
                },
                {
                    "text": {
                        "type": "plain_text",
                        "text": "*this is plain_text text*",
                        "emoji": true
                    },
                    "value": "value-1"
                }
            ],

例子:

{
    "type": "home",
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "checkboxes",
                "initial_options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-0"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-1"
                    }
                ],
                "options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-0"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-1"
                    }
                ],
                "action_id": "checkboxes-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Label",
                "emoji": true
            }
        }
    ]
}
于 2021-08-21T13:02:01.293 回答