Google Apps Menu - Function with parameter

折月煮酒 提交于 2019-12-11 08:26:02

问题


Let's say I have this function:

function alertar(userEmail) {
   var doc = DocumentApp.getActiveDocument();
   // Get the URL of the document.
   var url = doc.getUrl();
   // Send yourself an email with a link to the document.
   var u = Session.getActiveUser();

   ui.alert('it worked');
   GmailApp.sendEmail(userEmail, "assunto", "hey, click here" +  url);

}

And then I created menus as follows:

 var editors = DocumentApp.getActiveDocument().getEditors();
 var m = ui.createMenu('uPaPoPe Actions');
 var subMenu = ui.createMenu('Escritores');
 for (var i=0;i<editors.length;i++)
 {
   subMenu.addItem(editors[i].getEmail(), 'function()          {alertar("'+editors[i].getEmail()+'");}');  //line with problem
  }

How do I pass parameters to a function that requires them from a google apps script menu item? Doing any of the following constructions is not valid:

   subMenu.addItem(editors[i].getEmail(), 'function()          {alertar("'+editors[i].getEmail()+'");}');  


   subMenu.addItem(editors[i].getEmail(), 'alertar("'+editors[i].getEmail()+'");');  

This is allowed:

   subMenu.addItem(editors[i].getEmail(), 'alertar');  

But the latter does not allow me to pass the editor's email as parameter.

来源:https://stackoverflow.com/questions/20872214/google-apps-menu-function-with-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!