无法阅读财产" 0"来自undefined

时间:2014-10-28 14:58:28

标签: javascript typeerror

无法读取属性" 0"来自undefined。

我找不到问题

function sendSurvey() {
  var recipient = Browser.inputBox("Send Survey", "Enter Recipient Email", Browser.Buttons.OK_CANCEL);
  if (recipient === 'cancel') return;

  var subject = 'Commuting Survey';

  var scriptUrl = ScriptApp.getService().getUrl();
  if (!scriptUrl) throw new Error( 'You must Deploy as Web App first.' );

  var template = HtmlService.createTemplateFromFile('emailTemplate');
  template.scriptUrl = scriptUrl;
  template.serialNumber = getGUID();  // Generate serial number for this response
  var html = template.evaluate().getContent();
  var plainText = 'Please complete this survey online at: ' + scriptUrl;
  html += '<p>Alternatively, you may <A href="' + scriptUrl + '"> complete this survey online.</A>';

  GmailApp.sendEmail(recipient, subject, plainText, {htmlBody:html} );

  Browser.msgBox("Survey Sent");
}


function doGet() {
  // Build survey body
  var template = HtmlService.createTemplateFromFile('emailTemplate');
  template.scriptUrl = ScriptApp.getService().getUrl();
  template.serialNumber = getGUID();  // Generate serial number for this response
  var app = template.evaluate();
  return app;
}

function doPost(e) {
  Logger.log(e);
  var ss = SpreadsheetApp.openById(_spreadsheetId);
  var sheet = ss.getSheets()[0];  // Assume first sheet collects responses
  var row = [
    new Date(),                     // Timestamp
    e.parameters.serial[0],         // Serial Number
    e.parameters.pytanie1[0],        // Pytanie 1
    e.parameters.pytanie2[0],        // Pytanie 2
  ];
  var lock = LockService.getPublicLock();
  // Wait for up to 30 seconds for other processes to finish.
  var locked = lock.tryLock(30000);

  if (locked) {
    var rowNum = sheet.getLastRow()+1;
    sheet.getRange(rowNum, 1, 1, row.length).setValues([row]);

    // Release the lock so that other processes can continue.
    lock.releaseLock();
    var result = "Response Recorded: \n  "+row.join('\n  ');
  }
  else {
    // Failed to get lock
    result = "System busy, please try again.";
  }

  // Report result of POST, in plain text
  return ContentService.createTextOutput(result)
                       .setMimeType(ContentService.MimeType.TEXT);
}

无法读取属性&#34; 0&#34;来自undefined。

我找不到问题 无法阅读财产&#34; 0&#34;来自undefined。

我找不到问题 无法阅读财产&#34; 0&#34;来自undefined。

我找不到问题 无法阅读财产&#34; 0&#34;来自undefined。

我找不到问题

2 个答案:

答案 0 :(得分:0)

您遇到以下问题之一:

  • ss.getSheets 函数返回undefined (在我阅读文档后,我看到这不可能)
  • e.parameters 对象的其中一个属性不存在:
    • 串行
    • pytanie1
    • pytanie2

您可以添加一些 console.log 来查看哪些属性不存在...

答案 1 :(得分:0)

尝试在 e.parameters.pytanie2 [0]

之后删除逗号(,)

var row = [

new Date(),                     // Timestamp
e.parameters.serial[0],         // Serial Number
e.parameters.pytanie1[0],        // Pytanie 1
e.parameters.pytanie2[0]**,**        // Pytanie 2

];