首页 > 解决方案 > 需要变量A来声明变量B,但是需要变量B来声明变量A

问题描述

我正在制作一个工具来制作一个新的谷歌文档并将其通过电子邮件发送给我的老师以获取某个主题,但是我的变量“主题”需要包含文档链接,这意味着我需要在声明变量主题之前创建文档,但是,为了知道给文档起什么名字,我需要访问存储在变量 Subjects 中的信息。有什么建议么?我的javascript在下面。

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index.html');
}

function customDoc(subject) {

  var formattedDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'M/d/yyyy');
  
  var subjects = {
      'math': {
     email: 'teacher@example.com',
      preSubject: 'math for '
    },
    'la': {
     email: 'teacher@example.com',
      preSubject: 'la for '
    },
    'science': {
     email: 'teacher@example.com',
      preSubject: 'science for '
    },
    'is': {
  email: 'teacher@example.com',
      preSubject: 'I&S for '
    },
    'spanish': {
      email: 'teacher@example.com',
      preSubject: 'Español para '
    
      message:  'Español para ' + formattedDate + 'This is supposed to be where the link to the google doc is, so this is where the paradox comes in. '
    }
  };

 
  console.log('Today: ' + formattedDate);
  console.log('Subject: ' + subject);
  console.log(subjects[subject]);
GmailApp.sendEmail(subjects.email, subjects.preSubject, subjects.message)
}

标签: javascriptgoogle-apps-scriptgoogle-docs

解决方案


推荐阅读