Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在Google应用程序脚本中更改小部件KeyValue开关SetValue的值_Google Apps Script_Gmail Addons_Google Apps Script Addon - Fatal编程技术网

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())
...