将其他参数传递给Apps脚本事件对象

编程入门 行业动态 更新时间:2024-10-28 12:26:05
本文介绍了将其他参数传递给Apps脚本事件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Apps脚本中的回调和作用域感到头疼。我具有以下功能,该功能会为当前打开的电子邮件中的每个附加文件创建一个带有复选框的Gmail加载项部分:

I'm having a lot of headaches with callbacks and scopes in Apps Script. I have the following function, that creates a Gmail Add-On section with a checkbox for each attached file on the currently open email:

function createAttachmentsSection( attachments ){ var widget = CardService.newSelectionInput() .setFieldName( 'selectedFiles' ) .setType( CardService.SelectionInputType.CHECK_BOX ) .setOnChangeAction( CardService.newAction() .setFunctionName( 'checkboxAltered' ) ); for ( var i = 0 ; i < attachments.length; i++ ) widget.addItem( attachments[i].getName(), '' + i , true ) return CardService.newCardSection().addWidget( widget ); }

所有内容均按预期显示,但我希望用户也能够选择他要取消选中以供以后处理的文件。 在我的checkboxAltered函数中,我想处理用户选择输入操作,这是唯一可行的方法(据我从文档中了解到的那样。请告诉我我是否错!)。当前它是一个空函数,仅用于检查我的理解程度:

Everything is displayed as expected, but I want the user to be also able to select which files he wants to uncheck for later processing. In my checkboxAltered function I want to handle user selection input actions, which is the only way to go (as far as I've learned from the documentation. Please tell me if I'm wrong!). It's currently an empty function, only used to check how little I understand:

function checkboxAltered( e ){ Logger.log( e ); Logger.log( selections.length ); }

e ,事件对象,此处始终未定义。 选择(一个预先初始化并检查过的)全局布尔数组,每个附件都有一个项目,总是简单地 []

e, the event object, is always undefined here. And selections, a (previously initialized and checked) global bool array with an item for each attachment, is always simply [] inside checkboxAltered.

我在做什么错? 如何使用setParameters(Object)告诉回调函数内部用户单击了哪个复选框? 是否不能从回调函数访问全局变量?

What am I doing wrong? How can I use setParameters( Object ) to tell inside the callback function which checkbox was clicked by the user? Are global variables not accessible from callback functions?

推荐答案

查看CardService文档中的 Action 类的 setParameters() 方法。如果要将自定义参数传递给回调,则需要使用该方法。

Looking at the CardService documentation the Action class has a setParameters() method. If you want to pass custom parameters to the callback you'll need to use that method.

更多推荐

将其他参数传递给Apps脚本事件对象

本文发布于:2023-11-23 10:43:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621154.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   对象   参数   事件   Apps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!