What is the best way to manage two UI's?

后端 未结 3 582
别跟我提以往
别跟我提以往 2021-01-03 16:56

I have created two user interfaces. How can I close the first one and activate the next? Is it possible to have two UI under Google apps script?

I have try something

3条回答
  •  一整个雨季
    2021-01-03 17:43

    Here's and example of three dialogs shown one after the other, maintaining state/data between them via the CacheService object.

    (You could use UserProperties, ScriptProperties or even a Hidden Field as an alternative, each has their own scope though...)

    Hopefully this makes sense without explaining what each dialog in the UI Builder contains.

    function showDialog1(){
      var app = UiApp.createApplication();
      app.add( app.loadComponent("Dialog1") );
      SpreadsheetApp.getActiveSpreadsheet().show(app);
    }
    
    function onDialog1OKButton(e){
      CacheService.getPrivateCache().put("n1", e.parameter.n1);
    
      var app = UiApp.getActiveApplication();
      var d2 = app.loadComponent("Dialog2");
      app.add(d2);
    
      SpreadsheetApp.getActiveSpreadsheet().show(app);
    }
    
    function onDialog2OKButton(e){
      var c = CacheService.getPrivateCache();
      c.put("n2", e.parameter.n2);
    
      var app = UiApp.getActiveApplication();
      app.add(app.loadComponent("DialogResult")); 
    
      var n1 = c.get("n1");
      var n2 = c.get("n2");
      var l = app.getElementById("Label2");
      l.setText( "" + n1 + " + "  + n2 + " = " + (parseInt(n1) + parseInt(n2)) );
    
      SpreadsheetApp.getActiveSpreadsheet().show(app);
    }
    

提交回复
热议问题