【问题标题】:Can I change handler callbackfunction in another server handler我可以在另一个服务器处理程序中更改处理程序回调函数吗
【发布时间】:2012-11-19 23:34:30
【问题描述】:

我想在另一个服务器处理程序中更改回调函数。我收到响应“无法在对象 Generic 中找到函数 setCallbackFunction。”后果 app.getElementById('treeHandler').setCallbackFunction('noSelection'); 而处理程序在主线中定义为 var handler = app.createServerHandler('nameSelected').setId('treeHandler'); 所以看起来我们无法在服务器处理程序中获取 ServerHandler 类型的元素。

这是预期的行为吗?

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    没错;您无法将它们取回并对其进行任何处理。

    【讨论】:

    • 谢谢 Corey,一张关于 get 和 set 工作/不工作的小表格会有所帮助。
    • 任何小部件都应该是可检索的。除了处理程序之外,我想不出其他任何东西。
    【解决方案2】:

    这并不完全正确,您可以在应用程序中添加隐藏元素。只需通过使用 createHidden 而不是 createTextBox 来采用下面的 axmaple。

    function doGet() {
       var app = UiApp.createApplication();
       var textBox1 = app.createTextBox().setName("textBox1");
       var textBox2 = app.createTextBox().setId("textBox2");
       app.add(textBox1);
       app.add(textBox2);
       var textBox3 = app.createTextBox().setName("textBox3");
       var panel = app.createFlowPanel();
       panel.add(textBox3);
       app.add(panel);
       var button = app.createButton("a button");
       var handler = app.createServerHandler("handlerFunction");
       handler.addCallbackElement(textBox1)
           .addCallbackElement(textBox2)
           .addCallbackElement(panel)
       button.addClickHandler(handler);
       app.add(button);
       return app;
     }
    
     function handlerFunction(eventInfo) {
       var parameter = eventInfo.parameter;
       // There's a lot of information in 'parameter' about the event too, but we'll focus here
       // only on the callback elements.
       var textBox1 = parameter.textBox1;  // the value of textBox1
       var textBox2 = parameter.textBox2;  // undefined! setId is not the same as setName
       var textBox3 = parameter.textBox3;  // works! the parent "panel" was a callback element
     }
    

    来源:https://developers.google.com/apps-script/class_serverhandler#addCallbackElement

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      相关资源
      最近更新 更多