Class CardSection

CardSection

卡片部分包含 widget 组,并在它们之间提供视觉分隔。

适用于 Google Workspace 插件和 Google Chat 应用。

const image = CardService.newImage();
// Build image ...
const textParagraph = CardService.newTextParagraph();
// Build text paragraph ...

const cardSection = CardService.newCardSection()
                        .setHeader('Section header')
                        .addWidget(image)
                        .addWidget(textParagraph);

方法

方法返回值类型简介
addWidget(widget)CardSection将给定的 widget 添加到此部分。
setCollapseControl(collapseControl)CardSection设置该部分的可自定义展开和收起按钮。
setCollapsible(collapsible)CardSection设置该部分是否可以收起。
setHeader(header)CardSection设置该部分的标题。
setId(id)CardSection设置分配的唯一 ID,该 ID 用于标识要发生变化的部分。
setNumUncollapsibleWidgets(numUncollapsibleWidgets)CardSection设置在该部分收起时仍显示的 widget 数量。

详细文档

addWidget(widget)

将给定的 widget 添加到此部分。widget 会按照添加顺序显示。您无法向卡片部分添加超过 100 个 widget。

参数

名称类型说明
widgetWidget要添加到该部分的 widget。

返回

CardSection - 此对象,用于链式调用。


setCollapseControl(collapseControl)

设置该部分的可自定义展开和收起按钮。只有在该部分可以收起时,这些按钮才会显示。如果未设置此字段,系统会使用默认按钮。

适用于 Google Chat 应用。在 Google Workspace 插件的开发者预览版中提供。

const collapseButton =
    CardService.newTextButton()
        .setTextButtonStyle(CardService.TextButtonStyle.BORDERLESS)
        .setText('show less');

const expandButton =
    CardService.newImageButton()
        .setImageButtonStyle(CardService.ImageButtonStyle.FILLED)
        .setMaterialIcon(CardService.newMaterialIcon().setName('bug_report'));

const collapsibleSection =
    CardService.newCardSection()
        .setCollapsible(true)
        .setNumUncollapsibleWidgets(1)
        .setCollapseControl(
            CardService.newCollapseControl()
                .setHorizontalAlign(CardService.HorizontalAlignment.CENTER)
                .setCollapseButton(collapseButton)
                .setExpandButton(expandButton),
        );

参数

名称类型说明
collapseControlCollapseControl收起控件设置。

返回

CardSection - 此对象,用于链式调用。


setCollapsible(collapsible)

设置该部分是否可以收起。

参数

名称类型说明
collapsibleBoolean可收起设置。

返回

CardSection - 此对象,用于链式调用。


setHeader(header)

设置该部分的标题。可选。

参数

名称类型说明
headerString标题文本。

返回

CardSection - 此对象,用于链式调用。


setId(id)

设置分配的唯一 ID,该 ID 用于标识要发生变化的部分。插件仅支持部分变化。

参数

名称类型说明
idString该部分的 ID,长度上限为 64 个字符,格式为 `[a-zA-Z0-9-]+`。

返回

CardSection - 此对象,用于链式调用。


setNumUncollapsibleWidgets(numUncollapsibleWidgets)

设置在该部分收起时仍显示的 widget 数量。显示的 widget 始终是添加的第一个 widget。

参数

名称类型说明
numUncollapsibleWidgetsInteger要显示的 widget 数量。

返回

CardSection - 此对象,用于链式调用。