Google apps script 在Google应用程序脚本中更改小部件KeyValue开关SetValue的值
我不明白如何为开关设置值。我希望能够使用用户存储的值进行开/关操作 在上一页,他们展示了以下示例:Google apps script 在Google应用程序脚本中更改小部件KeyValue开关SetValue的值,google-apps-script,gmail-addons,google-apps-script-addon,Google Apps Script,Gmail Addons,Google Apps Script Addon,我不明白如何为开关设置值。我希望能够使用用户存储的值进行开/关操作 在上一页,他们展示了以下示例: var switchKeyValue = CardService.newKeyValue() .setTopLabel("Switch key value widget label") .setContent("This is a key value widget with a switch on the right") .setSw
var switchKeyValue = CardService.newKeyValue()
.setTopLabel("Switch key value widget label")
.setContent("This is a key value widget with a switch on the right")
.setSwitch(CardService.newSwitch()
.setFieldName("form_input_switch_key")
.setValue("form_input_switch_value") // <-- note that part
.setOnChangeAction(CardService.newAction()
.setFunctionName("handleSwitchChange")));
我可以说,即使没有提供值,它仍然是false/off
如何更改开关小部件的状态
setSelected
将设置开关的初始状态。您是英雄!非常感谢你!这么小的问题,如果您碰巧知道,setValue
为什么在那里?@KellyTheDev-setFieldName
不需要是唯一的。如果有多个具有相同名称的开关,则将返回一个值数组。因此,setValue
允许您为一组具有相同名称的交换机设置不同的值。
const value = true;
...
.setValue(value.toString())
...