且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

同时显示对话框和自定义侧边栏时关闭对话框

更新时间:2023-01-23 21:07:29

close() 方法关闭当前对话框/边栏,并且假设clickWeek()在您的边栏中,它将关闭它而不是对话框.您需要在对话框中运行close()方法.

The close() method closes the current dialog/sidebar, and asuming the clickWeek() is in your sidebar, it will close it instead of the dialog. You need to run the close() method inside the dialog.

如何在创建对话框时以及在withSuccessHandler()检测到成功的返回值时触发服务器端函数,然后使用close()关闭对话框.

How about you fire your server-side function when the dialog is created and when the withSuccessHandler() detects a successful return then it closes the dialog using close().

在创建由createHtmlOutput插入的对话框时,您将需要使用createHtmlOutputFromFile,并且在html内使用<script>标记.这是一个示例:

You will need to use createHtmlOutputFromFile when creating the dialog insted of createHtmlOutput and inside your html use the <script> tag. Here's an example:

code.gs

function createDialog(){
  var htmlOutput = HtmlService
       .createHtmlOutputFromFile('dialog')
       .setWidth(250)
       .setHeight(80);
   SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading');
}

function doBusyStuff(){
  // Busy stuff
}

dialog.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
    (function() {
      // Runs the busy stuff and closes the dialog using .close() on success
      google.script.run
          .withSuccessHandler(google.script.host.close)
          .doBusyStuff();
    })();
    </script>
  </head>
  <body>
  <p>Please wait a moment...</p>
  </body>
</html>