Javascript 链接函数如何访问Google应用程序脚本中的表单数据?

Javascript 链接函数如何访问Google应用程序脚本中的表单数据?,javascript,google-apps-script,Javascript,Google Apps Script,这个问题是“.”的延伸 我需要做一些类似的事情。。。复制/粘贴回答上一个问题的代码示例: var app = null; function firstHandler(e) { if( app == null ) app = UiApp.getActiveApplication(); //do your thing //now, instead "return app;" you return the second handler return secondHandler(

这个问题是“.”的延伸

我需要做一些类似的事情。。。复制/粘贴回答上一个问题的代码示例:

var app = null;
function firstHandler(e) {
  if( app == null )
    app = UiApp.getActiveApplication();
  //do your thing
  //now, instead "return app;" you return the second handler
  return secondHandler(e);
}

function secondHandler(e) {
  if( app == null )
    app = UiApp.getActiveApplication();
  //do your job
  return app;
}
其中firstHandler()是按钮的单击处理程序。这个例子和我需要做的不同之处在于,在我的例子中,secondHandler()需要从表单中提取一条信息。具体来说,我需要从列表框中获取所选值

通常,我让secondHandler()拉入该信息的方法是将包含列表框的父对象传递到函数中,然后有一行如下所示:

var value = eventInfo.parameter.listBoxName;
但是,我无法将列表框所在的网格传递到secondHandler()。以下是我尝试过的:

var app = null;
function firstHandler(e) {
  if( app == null )
    app = UiApp.getActiveApplication();
  //do your thing
  //get the object now, pass it into the chained function
  var myGrid = app.getElementById("gridId");
  return secondHandler(myGrid);
}

function secondHandler(e) {
  if( app == null )
    app = UiApp.getActiveApplication();
  var value = e.parameter.listBoxName.toString();
  //do your job
  return app;
}
但这一直不起作用。我还尝试将secondHandler()修改为完全无参数,这样我就可以避免将网格传递到firstHandler()中的secondHandler():

这也不行。。。“app.getElementById('listBoxId').value”似乎没有返回任何内容。我不知道为什么不:(

有没有想过如何做到这一点?有没有人知道为什么我的app.getElementById解决方案没有按预期运行?感谢所有帮助!!!

试试这个

function firstHandler(e) {
  var app = UiApp.getActiveApplication();
  //do your thing
  return secondHandler(e);
}

function secondHandler(e) {
  var app = UiApp.getActiveApplication();
  var value = e.parameter.listBoxName;
  //do your job
  return app;
}
确保在创建处理程序时使用此选项

app.createServerHandler("firstHandler").addCallbackElement(gridContainingListBox);

如果要从页面中检索值,则必须使用
e.parameter
,该参数在添加适当的回调元素时已正确设置。如果要修改UI中的元素,则当然可以使用
app.getElementById(…).whateverFunction()
,但请注意,您不能调用
getValue()
,等等。

尝试将
var-app=null;
替换为
var-app;
。我相信在函数外部设置一个变量会使其保持不变。如果(app==null),您当然可以使用
if
行,但我从未遇到过两次调用getActiveApplication()的问题。
app.createServerHandler("firstHandler").addCallbackElement(gridContainingListBox);