Google apps script 库中的未知宏

Google apps script 库中的未知宏,google-apps-script,Google Apps Script,我正在尝试创建一个库,到目前为止进展顺利,但在添加了一些函数之后,它就坏了 当我从编辑器运行脚本时,它是在脚本中编写的。但当我尝试测试它时,脚本无法识别服务器处理程序,并给出一个错误:未知宏处理程序\函数\名称 我检查过了,处理程序中的所有名称都对应于函数的名称。我读到一些人有问题,因为代码在不同的文件中,移动了同一文件中的所有代码,问题仍然存在 并不是所有的处理程序都是这样的 还有什么其他原因呢 编辑: 作为对“点击”的响应,应用程序会在运行期间创建额外的面板。这些面板上元素的处理程序是应用程

我正在尝试创建一个库,到目前为止进展顺利,但在添加了一些函数之后,它就坏了

当我从编辑器运行脚本时,它是在脚本中编写的。但当我尝试测试它时,脚本无法识别服务器处理程序,并给出一个错误:未知宏处理程序\函数\名称

我检查过了,处理程序中的所有名称都对应于函数的名称。我读到一些人有问题,因为代码在不同的文件中,移动了同一文件中的所有代码,问题仍然存在

并不是所有的处理程序都是这样的

还有什么其他原因呢

编辑:

作为对“点击”的响应,应用程序会在运行期间创建额外的面板。这些面板上元素的处理程序是应用程序无法“找到”的宏(即处理程序函数)的处理程序

如何解决这个问题? (除了将所有面板放置在原始面板中,然后更改可见性的解决方案外,这对处理程序来说是可行的,但会引发其他问题)

所以在这里放一些代码,这是非常非常简单的代码

function notWorkingGUI(){

  var app=UiApp.createApplication();
  var appPanel=app.createVerticalPanel().setId("appPanel");
  var handler1=app.createServerHandler("handlerFunction1").addCallbackElement(appPanel);
  var firstButton=app.createButton("Button 1", handler1);

  appPanel.add(firstButton);
  app.add(appPanel);

  SpreadsheetApp.getActive().show(app);

}

function handlerFunction1(e){

  var app=UiApp.getActiveApplication();

  var appPanel2=app.createVerticalPanel().setId("appPanel2").setStyleAttribute("zIndex", 0).setStyleAttribute("position", "fixed");
  var handler2=app.createServerHandler("handlerFunction2").addCallbackElement(appPanel2);
  var secondButton=app.createButton("Button 2", handler2);
  var label=app.createLabel("This should get visible after the click").setId("label").setVisible(false);

  appPanel2.add(secondButton).add(label);
  app.add(appPanel2);

  return app;


}

function handlerFunction2(e){

  var app=UiApp.getActiveApplication();

  app.getElementById("label").setVisible(true);

  return app;

}
当从编写它的编辑器执行时,它将按预期工作,即它将显示firstButton,然后是secondButton,最后是标签,但是如果它将作为库发布并从其他脚本调用,它将只识别functionHandler1,即show firstButton,secondButton但单击secondButton后,将看到错误消息

但是,如果脚本是这样编写的:

function workingGUI(){

  //previous first part
  var app=UiApp.createApplication();
  var appPanel=app.createVerticalPanel().setId("appPanel");
  var handler1=app.createServerHandler("handlerFunction1a").addCallbackElement(appPanel);
  var firstButton=app.createButton("Button 1", handler1);


  //previous second part
  var appPanel2=app.createVerticalPanel().setId("appPanel2").setStyleAttribute("zIndex", 0).setStyleAttribute("position", "fixed");
  var handler2=app.createServerHandler("handlerFunction2a").addCallbackElement(appPanel2);
  var secondButton=app.createButton("Button 2", handler2).setId("button2");


  appPanel.add(firstButton);
  app.add(appPanel);

  SpreadsheetApp.getActive().show(app);

}

function handlerFunction1a(e){

  var app=UiApp.getActiveApplication();



  var label=app.createLabel("This should get visible after the click").setId("label").setVisible(false);

  app.getElementById("appPanel2").add(app.getElementById("button2")).add(label);
  app.add(app.getElementById("appPanel2"));

  return app;


}

function handlerFunction2a(e){

  var app=UiApp.getActiveApplication();

  app.getElementById("label").setVisible(true);

  return app;

}
请注意,所有处理程序都必须在main函数中定义,这意味着使用这些处理程序的所有元素以及所有回调元素都必须在这里定义。
然后,它甚至可以作为一个库工作,但是由于某种原因,即使对于这样一个简单的示例,这也会使脚本速度慢得多

我解决了这个问题,它使脚本速度稍微慢了一点,但是如果您在原始函数中定义所有处理程序(这意味着所有UI元素),它将正常工作

问题在于:

它调用的是本地代码,而不是库代码

我想知道如果在本地代码中添加存根函数是否仍然很慢

i、 e


请您发布库的项目密钥,以便我可以尝试将其包括在内,或者在此处发布代码。很抱歉,无法在此处发布库的代码,但我可以发布类似的代码(这将产生相同的问题),或者通过g+与我联系。通过将所有代码放在一个文件中解决了该问题,速度快得多。在编写脚本时,我根据处理程序和它们的助手函数的响应来划分它们,基本上每个按钮都有它的文件,在合并了所有这些之后,它变得更好了。
function runthis() {
  library.createGUI();
}
function myevent() {
 library.myevent();
}