刷新Google脚本HTML服务中的div或整个页面 [英] Refresh a div or whole page in Google Script HTML Service

查看:71
本文介绍了刷新Google脚本HTML服务中的div或整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法刷新Google Apps脚本中的HTML页面或div内容。我在编程方面自学,所以我对整个努力了解甚少。基本上,我有一个应用程序,一旦用户点击一个按钮,它就会更改Google文档中的信息,并刷新应用程序来显示更改。我需要帮助刷新部分。



以下是html服务部分的一个片段:

 <?!= include('Stylesheet'); ?> 
<? var data = getData(); ?>
<? var data2 = get2Data(); ?>
...
< div class =inline mainbody>
< div class =title>
< / div>
< div class =section group>
< div class =col span_1_of_2>
< div class =newreq>
< table>
< h2>新请求< / h2>
<? for(var i = 0; i< data.length; i ++){?>
<? for(var j = 0; j< data [i] .length; j ++){>
<?如果((data [i] [23] =='None')&&(data [i] [29]!=Done)&&(data [i] [30]!=Yes )&&(data [i] [31]!=Yes)){?>
< tr>
< td>
< b>名称:< / b> <?= data [i] [3]?>& nbsp;& nbsp;& nbsp;< b>学校:< / b> <?= data [i] [5]?>& nbsp;& nbsp;& nbsp;< b>程式类型:< / b> <?= data [i] [1]?><?= data [i] [2]?>
< br>
< p>< b>首选:< / b> <?= data [i] [19]?>& nbsp;& nbsp;< input onclick =google.script.run.finalTime('<?= data [i] [ 24]→>','First')type =buttonvalue =Finalize First Choice>
< / p>
< p>< b>第二选择:< / b> <?= data [i] [20]?>& nbsp;& nbsp;< input onclick =google.script.run.finalTime('<?= data [i] [ 24]→>','Second')type =buttonvalue =完成第二选择>
< / p>
< p>< b>第三选择:< / b> <?= data [i] [21]?>& nbsp;& nbsp;< input onclick =google.script.run.finalTime('<?= data [i] [ 24]→>','第三')type =buttonvalue =Finalize Third Choice>
< / p>
< p>< input onclick =google.script.run.deletePre('<?= data [i] [24]?>')type =buttonvalue =Delete类= 按钮 >
< / p>
< br>
< / td>
<?打破?>
<? }?>
< / tr>
<? }?>
<? }?>
< / table>
< / div>
< / div>

基本上,脚本从电子表格中提取信息。一旦我点击一个按钮,是否可以刷新脚本甚至页面,以便用户不必手动操作?我尝试搜索类似的查询而没有有意义的结果,我尝试添加.reload()和.html(data)并不是很有效。任何想法如何解决这个问题?解决方案

老线程,但也许这会帮助别人......如何重建和显示整个页面...



属于index.html的一部分

 < ; div id =refreshonclick =google.script.run 
.withSuccessHandler(refreshApp)
.getNewHtml()>
刷新
< / div>

< script>
函数refreshApp(newHtml){
document.open();
document.write(newHtml);
document.close();
}
< / script>

部分代码.gs

  function getNewHtml(e){
var html = HtmlService
.createTemplateFromFile('index')//使用模板化html
.evaluate()
.getContent();
返回html;
}


I am having difficulty with refreshing the HTML page or div content in a Google Apps Script. I am self-taught at programming so I have very little knowledge in the whole endeavor; please bear with me on my mess of code.

Basically, I have an application that once the user clicks on a button, it changes the information within Google Docs and refreshes the application to show the changes. I need help with the refresh part.

Here is a snippet of the html service part:

<?!= include('Stylesheet'); ?>
<? var data = getData(); ?>
<? var data2 = get2Data(); ?>
...
<div class="inline mainbody">
    <div class="title">
    </div>
    <div class="section group">
        <div class="col span_1_of_2">
            <div class="newreq">
                <table>
                    <h2>New Requests</h2>
                    <? for (var i = 0; i < data.length; i++) { ?>
                    <? for (var j = 0; j < data[i].length; j++) { ?>
                        <? if ((data[i][23] == 'None') && (data[i][29] != "Done") && (data[i][30] != "Yes") && (data[i][31] != "Yes")) { ?>
                        <tr>
                            <td>
                                <b>Name:</b> <?= data[i][3] ?>&nbsp;&nbsp;&nbsp;<b>School:</b> <?= data[i][5] ?>&nbsp;&nbsp;&nbsp;<b>Program Type:</b> <?= data[i][1] ?><?= data[i][2] ?>
                                <br>
                                <p><b>First Choice at:</b> <?= data[i][19] ?>&nbsp;&nbsp;&nbsp;<input onclick="google.script.run.finalTime('<?= data[i][24] ?>','First')" type="button" value="Finalize First Choice">
                                </p>
                                <p><b>Second Choice at:</b> <?= data[i][20] ?>&nbsp;&nbsp;&nbsp;<input onclick="google.script.run.finalTime('<?= data[i][24] ?>','Second')" type="button" value="Finalize Second Choice">
                                </p>
                                <p><b>Third Choice at:</b> <?= data[i][21] ?>&nbsp;&nbsp;&nbsp;<input onclick="google.script.run.finalTime('<?= data[i][24] ?>','Third')" type="button" value="Finalize Third Choice">
                                </p>
                                <p><input onclick="google.script.run.deletePre('<?= data[i][24] ?>')" type="button" value="Delete" class="button">
                                </p>
                                <br>
                            </td>
                        <? break ?>
                        <? } ?>
                        </tr>
                    <? } ?>
                    <? } ?>
                </table>
            </div>
        </div>

Basically the script pulls information from the spreadsheet. Is is possible once I click a button, that it refreshes the script or even the page so that the User does not have to manually? I tried searching similar inquires without meaningful result and my attempts of adding ".reload()" and ".html(data)" aren't quite working. Any ideas how I can tackle this?

解决方案

Old thread but maybe this will help someone... How to rebuild and display the entire page...

part of index.html

    <div id="refresh" onclick ="google.script.run
        .withSuccessHandler(refreshApp)
        .getNewHtml()">
    Refresh
    </div>

    <script>
      function refreshApp(newHtml) {
        document.open();
        document.write(newHtml);
        document.close();
      }
    </script>

part of code.gs

    function getNewHtml(e) {
      var html = HtmlService
        .createTemplateFromFile('index') // uses templated html
        .evaluate()
        .getContent();
      return html;
    }

这篇关于刷新Google脚本HTML服务中的div或整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆