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

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

问题描述

我正在通过 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();

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

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 Script .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天全站免登陆