2012-12-06 65 views
0

我有這個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

嘗試刪除3個「返回應用」行。這似乎對我有用。 show方法會自動將其放在電子表格中。

+0

工作正常! ty @ Kalyan –