卡片部分包含 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);
方法
| 方法 | 返回值类型 | 简介 |
|---|---|---|
add | Card | 将给定的 widget 添加到此部分。 |
set | Card | 设置该部分的可自定义展开和收起按钮。 |
set | Card | 设置该部分是否可以收起。 |
set | Card | 设置该部分的标题。 |
set | Card | 设置分配的唯一 ID,该 ID 用于标识要发生变化的部分。 |
set | Card | 设置在该部分收起时仍显示的 widget 数量。 |
详细文档
addWidget(widget)
将给定的 widget 添加到此部分。widget 会按照添加顺序显示。您无法向卡片部分添加超过 100 个 widget。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
widget | Widget | 要添加到该部分的 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), );
参数
| 名称 | 类型 | 说明 |
|---|---|---|
collapse | Collapse | 收起控件设置。 |
返回
CardSection - 此对象,用于链式调用。
setCollapsible(collapsible)
setHeader(header)
setId(id)
设置分配的唯一 ID,该 ID 用于标识要发生变化的部分。插件仅支持部分变化。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
id | String | 该部分的 ID,长度上限为 64 个字符,格式为 `[a-zA-Z0-9-]+`。 |
返回
CardSection - 此对象,用于链式调用。
setNumUncollapsibleWidgets(numUncollapsibleWidgets)
设置在该部分收起时仍显示的 widget 数量。显示的 widget 始终是添加的第一个 widget。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
num | Integer | 要显示的 widget 数量。 |
返回
CardSection - 此对象,用于链式调用。