如何知道单击了哪个菜单项? [英] How to know which menu item was clicked?

查看:102
本文介绍了如何知道单击了哪个菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Google电子表格中的REST调用创建动态自定义菜单.每次通话我都会收到我想用作菜单项的不同运动

I'm creating a dynamic custom menu from REST call in google spreadsheet. With every call I receive different sports that I want to use as menu items

  // sample sports array
  var menuItemsArr = ['Footbal', 'Tennis', 'Swimming'];

  var menu = SpreadsheetApp.getUi().createMenu("Sports");
  for (i in menuItemsArr){
      menu.addItem(menuItemsArr[i],'createSheet')
       .addSeparator()
  }
  menu.addToUi();

当用户单击菜单项时,我要创建一个带有标题的新表-被单击的运动.因此,如果用户选择网球",我想创建一个名称为网球"的工作表.

When the user clicks on menu item I want to create a new sheet with title - the sport that was clicked. So if the user choose Tennis I want to create a sheet with name Tennis.

是否可以知道单击了哪个菜单项(以某种方式获得该项目的名称(网球),或者至少知道了被单击的菜单项的索引?

Is it possible to know which menu item was clicked (to take the name of the item (Tennis) somehow, or at least the index of the menu item that was clicked?

任何帮助将不胜感激!谢谢.

Any help will be appreciated! Thanks.

推荐答案

Google Apps脚本.createMenu和.createAddonMenu能够通过名称将其作为字符串调用函数,并且仅在Apps Script项目全局范围内查找具有该名称的函数

Google Apps Script .createMenu and .createAddonMenu are able to call functions by their name as string and only looks for functions with that name on the Apps Script project global scope.

另一种方法是通过使用带有对话框或工具栏的HTML服务来创建用户界面.

The alternative is to create your user interface by using a dialog or sidebar with the HTML Service.

这篇关于如何知道单击了哪个菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆