Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript e、 参数Google Apps脚本教程未定义错误_Javascript_Google Apps Script - Fatal编程技术网

Javascript e、 参数Google Apps脚本教程未定义错误

Javascript e、 参数Google Apps脚本教程未定义错误,javascript,google-apps-script,Javascript,Google Apps Script,我试图在此[link][1]处使用以下代码浏览UI服务教程:当我运行它时,我收到一个错误,指出e.parameter.userName中的参数未定义。我将处理程序从app.createServerClickHandler更改为app.createServerHandler,因为前面的显示已弃用。我该怎么过这关?教程是错误的还是误导了我?我看了又看,最后复制并粘贴了代码,但仍然是相同的错误 unction doGet(e) { var doc = SpreadsheetApp.openById

我试图在此[link][1]处使用以下代码浏览UI服务教程:当我运行它时,我收到一个错误,指出e.parameter.userName中的参数未定义。我将处理程序从app.createServerClickHandler更改为app.createServerHandler,因为前面的显示已弃用。我该怎么过这关?教程是错误的还是误导了我?我看了又看,最后复制并粘贴了代码,但仍然是相同的错误

unction doGet(e) {
  var doc = SpreadsheetApp.openById(SPREADSHEET_ID_GOES_HERE);
  var app = UiApp.createApplication().setTitle('New app');

  // Create the entry form, a 3 x 2 grid with text boxes for name, age, and city that is then added to a vertical panel
  var grid = app.createGrid(3, 2);
  grid.setWidget(0, 0, app.createLabel('Name:'));
  grid.setWidget(0, 1, app.createTextBox().setName('userName').setId('userName'));
  grid.setWidget(1, 0, app.createLabel('Age:'));
  grid.setWidget(1, 1, app.createTextBox().setName('age').setId('age'));
  grid.setWidget(2, 0, app.createLabel('City'));
  grid.setWidget(2, 1, app.createTextBox().setName('city').setId('city'));

  // Create a vertical panel and add the grid to the panel
  var panel = app.createVerticalPanel();

  panel.add(grid);

  // Here's where this script diverges from the previous script.
  // We create a horizontal panel called buttonPanel to hold two buttons, one for submitting the contents of the form
  // to the Spreadsheet, the other to close the form.

  var buttonPanel = app.createHorizontalPanel();

  // Two buttons get added to buttonPanel: button (for submits) and closeButton (for closing the form)
  // For the submit button we create a server click handler submitHandler and pass submitHandler to the button as a click handler.
  // the function submit gets called when the submit button is clicked.
  var button = app.createButton('submit');
  var submitHandler = app.createServerClickHandler('submit');
  submitHandler.addCallbackElement(grid);
  button.addClickHandler(submitHandler);
  buttonPanel.add(button);

  // For the close button, we create a server click handler closeHandler and pass closeHandler to the close button as a click handler.
  // The function close is called when the close button is clicked.
  var closeButton = app.createButton('close');
  var closeHandler = app.createServerClickHandler('close');
  closeButton.addClickHandler(closeHandler);
  buttonPanel.add(closeButton);


  // Create label called statusLabel and make it invisible; add buttonPanel and statusLabel to the main display panel.
  var statusLabel = app.createLabel().setId('status').setVisible(false);
  panel.add(statusLabel);

  panel.add(buttonPanel);

  app.add(panel);
  return app;
}

// Close everything return when the close button is clicked
function close() {
  var app = UiApp.getActiveApplication();
  app.close();
  // The following line is REQUIRED for the widget to actually close.
  return app;
}

// function called when submit button is clicked
function submit(e) {

  // Write the data in the text boxes back to the Spreadsheet
  var doc = SpreadsheetApp.openById(SPREADSHEET_ID_GOES_HERE);
  var lastRow = doc.getLastRow();
  var cell = doc.getRange('a1').offset(lastRow, 0);
  cell.setValue(e.parameter.userName);
  cell.offset(0, 1).setValue(e.parameter.age);
  cell.offset(0, 2).setValue(e.parameter.city);

  // Clear the values from the text boxes so that new values can be entered
  var app = UiApp.getActiveApplication();
  app.getElementById('userName').setValue('');
  app.getElementById('age').setValue('');
  app.getElementById('city').setValue('');
  // Make the status line visible and tell the user the possible actions
  app.getElementById('status').setVisible(true).setText('User ' + e.parameter.userName + ' entered.' +
  'To add another, type in the information and click submit. To exit, click close.');
  return app;
}​


  [1]: https://developers.google.com/apps-script/guides/ui-service#doGetParams

您可能以错误的方式测试此脚本

您是否正在使用.dev url测试代码

每个Web应用程序实际上有2个URL: 显示为以.exec结尾的应用程序的url,以及返回脚本最新保存版本的测试url,您必须使用该url按编辑/保存代码时的状态测试代码

.exec版本对应于您在部署窗口中选择的版本,如下所示。

此代码中的另一个问题是关闭功能,在已部署的Web应用程序中,应用程序将永远不会以这种方式关闭或隐藏。。。它仅在嵌入文档或电子表格等时才有效,而不是在独立应用程序中

你最终可以“模拟”一个“关闭”是使网格内容不可见,但这就是全部