Google Apps脚本查找功能来电号码 [英] Google Apps Script Find function caller id

查看:81
本文介绍了Google Apps脚本查找功能来电号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google Apps脚本,可以动态生成按钮并为每个ClickHandler分配一个ClickHandler,然后调用一个函数。
我的问题是,因为每个按钮调用相同的功能,我无法找到一种方法来确定他们实际上打了电话。这是一个代码示例:

I have a Google Apps Script that dynamically generates buttons and assigns for each a ClickHandler which in turn calls a function. My problem is that because every button calls the same function I can't find a way to indentify which of them actually made the call. Here is a code sample:

var handler = app.createServerHandler("buttonAction");
for (i=1,...) {
  app.createButton(...).setId(i).addClickHandler(handler);
}
function buttonAction() {
  //How do I know what button made the call?
}


推荐答案

另一个选择是使用e.parameter.source值来确定触发serverHandler的元素的ID。

Another option is to use the e.parameter.source value to determine the ID of the element that triggered the serverHandler to be called.

以下是一个示例:

Here's an example:

function doGet(e) {
  var app = UiApp.createApplication();
  var handler = app.createServerHandler("buttonAction");

  for (var i = 0; i < 4; i++) {
    app.add(app.createButton('button'+i).setId(i).addClickHandler(handler));
  }
  return app;
}


function buttonAction(e) {
  var app = UiApp.getActiveApplication();
  Logger.log(e.parameter.source);    
}

e.parameter.source将包含元素的ID,您可以然后用来调用app.getElementById(e.parameter.source)...

e.parameter.source will contain the ID of the element, which you could then use to call app.getElementById(e.parameter.source) ...

这篇关于Google Apps脚本查找功能来电号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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