下拉列表有错误

时间:2012-12-06 22:50:48

标签: google-apps-script

我有这个UiApp,它在下拉列表中为用户提供了两个不同的选项。用户有两个选项,当他们选择其中一个uiapp来并显示一些信息时,它有一个按钮可以返回到原始菜单。我遇到的问题是,当我做出选择时,我收到一条错误,上面写着“遇到错误:发生意外错误”。当我点击选项1和2上的返回按钮时会发生同样的情况。这是GAS的错误,还是不应该存在的代码?

谢谢!

 function Menu(e) {
  var app = UiApp.createApplication().setTitle(" Title"); 
  var dropDownList = app.createListBox().setName('list').setId('list');
  var infoLabel = app.createLabel('Scroll around to select the service     desired').setId('infoLabel');
//addItems  
  dropDownList.addItem("Options");
  dropDownList.addItem("Option1");
  dropDownList.addItem("Option2");

  var handler = app.createServerClickHandler('changeMe');
  handler.addCallbackElement(dropDownList);  
  dropDownList.addChangeHandler(handler);
  app.add(dropDownList);
  app.add(infoLabel);
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  spreadsheet.show(app);
  return app;
  }

  function changeMe(e) {
      if(e.parameter.list === 'Option1'){
        var app1 = UiApp.createApplication();
        var html1 = app1.add(app1.createHTML("<p><i>Hello you have selected Option  1</i>    </p>")).setHeight(800).setWidth(600);
        var button1 = app1.createButton('Go back').setId("button1");
        app1.add(button1);
        var handler2 = app1.createServerHandler('Menu');
        button1.addClickHandler(handler2); 
        var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
        spreadsheet.show(app1);
        return app1;
        }

  else if (e.parameter.list === 'Option2'){;
     var app2 = UiApp.createApplication();
     var html2 = app2.add(app2.createHTML("Hello You have selected Option2"));
     var button2 = app2.createButton('Go back').setId("button");
     app2.add(button2);
     var handler2 = app2.createServerHandler('Menu');
     button2.addClickHandler(handler2);                                                                  
     var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
     spreadsheet.show(app2);
     return app2;
     }
   }

1 个答案:

答案 0 :(得分:1)

尝试删除3“返回应用”行。这似乎对我有用。 show方法会自动将其放在电子表格中。