简体   繁体   English

在 html 文件中显示来自应用程序脚本文件的数组

[英]Show array from apps script file in html file

I have an array of email drafts that I got in apps script.我在应用程序脚本中收到了一系列电子邮件草稿。 I want to show them in a html file in a select element, but it shows up blank when I run it.我想在一个选择元素的 html 文件中显示它们,但是当我运行它时它显示为空白。 Code below下面的代码

code.gs代码.gs

function doGet(e) {
  return HtmlService.createHtmlOutput("index");
}


function doSomething() {

  var drafts = GmailApp.getDrafts();
  var drafty = [];
  for(var i = 0; i < drafts.length; i++){
    drafty.push(drafts[i].getMessage().getSubject());
  }
  Logger.log(drafty);
  return drafty;

  var select = document.getElementById("select"),
      arr = drafty;

  for(var i = 0; i < arr.length; i++)
  {
       var option = document.createElement("OPTION"),
          txt = document.createTextNode(arr[i]);

        option.setAttribute("value", arr[i]);
        option.appendChild(txt);
        document.getElementById("select").appendChild(option);
  }

index.html索引.html

<!DOCTYPE html>
<html>
  <head>
    <script>
      google.script.run.doSomething();
    </script>
  </head>
  <body>
    <select id="select" class="addon-select addon-form-input"></select>
  </body>

Something like this: gs:像这样:gs:

function doSomething() {
  var drafts=GmailApp.getDrafts();
  var drafty=[];
  for(var i=0;i<drafts.length;i++){
    drafty.push(drafts[i].getMessage().getSubject());
  }
  Logger.log(drafty);
  return drafty;
}

html: html:

<!DOCTYPE html>
<html>
  <head>
    <script>
      google.script.run
      .withSuccessHandler(function(A){
        var id='select';
        var select = document.getElementById(id);
        select.options.length = 0; 
        for(var i=0;i<A.length;i++) {
          select.options[i] = new Option(A[i],A[i]);
        }
      })
      .doSomething();
    </script>
  </head>
  <body>
    <select id="select"></select>
  </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数组从 javascript(Google Apps 脚本)添加到 html 文件 - Add array to a html file from javascript (Google Apps Script) 在应用程序脚本中分离 html 文件 - Separating html file in apps script 从 google 应用程序脚本中的 html 文件调用 javascript 函数 - Call javascript function from html file in google apps script 来自 Gsheet 的 html 文件中的 Google Apps 脚本动态项目符号列表 - Google Apps Script dynamically bulleted list in an html file from Gsheet 来自 Gsheet 的 html 文件中的 Google Apps 脚本动态表格行 - Google Apps Script dynamically table row in an html file from Gsheet 如何从外部 Html 文件获取 Google Apps 脚本中的 ElementById? - How to getElementById in Google Apps Script from external Html file? Google Apps脚本-将来自应用脚本功能的输出返回给html文件javascript函数 - Google Apps Script - return output from apps script function back to the html file javascript function 如何从另一个HTML文件中的一个HTML Apps脚本文件获取JSON数据? - How do I get JSON data from one HTML Apps Script file in another HTML file? Google Apps脚本WebApp将html传递到文件 - Google Apps Script WebApp Pass html to file 如何将变量从HTML脚本文件传递到Google Apps脚本中的javascript函数? - How can I pass a variable from an HTML script file to a javascript function in google apps script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM