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

编程入门 行业动态 更新时间:2024-10-28 14:30:34
本文介绍了同时显示对话框和自定义侧边栏时关闭对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用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>

更多推荐

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

本文发布于:2023-08-02 17:13:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   侧边   自定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!