我在使用google.script.host.close()命令时遇到了麻烦,因为它关闭了侧边栏而不是对话框.
I'm having trouble with the google.script.host.close() command in that it is closing my sidebar rather than the dialog.
function clickWeek() { setWeekColor('week', '#7FFF00'); setMonthColor('month', '#d6d6c2'); setPressColor('press', '#d6d6c2'); setAllDataColor('allData', '#d6d6c2'); google.script.run.withSuccessHandler(google.script.host.close).weekAheadCreate(); }该对话框从weekAheadCreate()功能的顶部打开,如下所示:
The dialog is opened from the top of the weekAheadCreate() fucntion as per below:
var htmlOutput = HtmlService .createHtmlOutput('<p>Please wait a moment...</p>') .setWidth(250) .setHeight(80); SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading');有什么想法可以强制google.script.host.close()作用于对话框而不是边栏吗?
Any ideas how I can force the google.script.host.close() to act on the dialog rather than the sidebar?
推荐答案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>更多推荐
同时显示对话框和自定义侧边栏时关闭对话框
发布评论