对象记录null而不是日历数据

时间:2014-02-13 17:16:29

标签: google-apps-script

我有一个HTML服务应用程序,要求参加课程的日期。当您选择日期时,它会为您提供复选框,类标题和类说明。您可以检查要参加的课程,然后单击“参加”按钮以记录数据。我接到了对log的调用,因为它记录了一些东西,但它始终是'null'而不是选中的事件。

这是我的code.gs:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('index.html').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}

function listEvents(dateSelected) {

  var calendar = CalendarApp.getCalendarById('CalendarID').getEventsForDay(new Date(dateSelected));
  if (calendar[0] == null) {
    var text = 'No classes for this date';
    return text;
  }
  else {
    var text = '<form id="eventsForm">';
    for (var i=0; i < calendar.length; i++) {
      text += "<input type='checkbox' name=";
      text += i+1;
      text += " value=";
      text += calendar[i].getTitle();
      text += ">";
      text += calendar[i].getTitle();
      text += ' - ';
      text += calendar[i].getDescription();
      text += '<br>';
    }
    text += "<input type='button' value='Attend' onclick='google.script.run.withSuccessHandler(test).processForm(this.parentnode)' />";
    text += "</form>";
    return text; 
  }
}

function processForm(x) {
  Logger.log(x);
}

这是HTML:

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/redmond/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>


<div class="container" >
    <div>
      <h1>Welcome to the sign up page</h1>
      <p>Please select a date for the class you'd like to attend below.</p>
      <p>Click Here: <input type="text" name="date" id="datepicker" /><p> 
    </div>
</div>
<div id='test'></div>

<script>
$("#datepicker").datepicker();
$("#datepicker").on("change", function () {
var dateSelected = $(this).val()
google.script.run.withSuccessHandler(onSuccess).listEvents(dateSelected);
});

function onSuccess(eventText) {
  document.getElementById('test').innerHTML=eventText;
}

</script>

单击“出席”按钮后,它会转到code.gs和logs中的processFrom,但正如我所说,它只记录日期/时间和“null”而不是类。我只是想检查一下我得到的东西,以便我可以将人们检查的课程发送到电子表格以显示谁将要来。关于如何让表单发回正确数据的任何想法?

1 个答案:

答案 0 :(得分:0)

当你看到它时,你会惊呆了! 将“this.parentnode”重命名为“this.parentNode”

这里你的脚本工作:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('index.html').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}

function listEvents(dateSelected) {
  Logger.log("dateSeleted: "+dateSelected);
  var selDate = new Date(dateSelected);
  Logger.log(selDate);
  var calendar = CalendarApp.getCalendarById('CalendarID').getEventsForDay(new Date(dateSelected));
  if (calendar[0] == null) {
    var text = 'No classes for this date';
    return text;
  }
  else {
    var text = '<form id="eventsForm">';
    for (var i=0; i < calendar.length; i++) {
      text += "<input type='checkbox' name=";
      text += i+1;
      text += " value=";
      text += calendar[i].getTitle();
      text += ">";
      text += calendar[i].getTitle();
      text += ' - ';
      text += calendar[i].getDescription();
      text += '<br>';
    }
    text += "<input type='button' value='Attend' onclick='google.script.run.withSuccessHandler(test).processForm(this.parentNode)' />";
    text += "</form>";
    return text; 
  }
}

function processForm(x) {
  Logger.log("x: "+JSON.stringify(x));
}

这也发生在我身上,我讨厌当我做这种错误时,我找了几个小时的解决方案 祝你的其他代码好运!

相关问题