Javascript 在Google应用程序脚本中迭代单选按钮值时出现问题

Javascript 在Google应用程序脚本中迭代单选按钮值时出现问题,javascript,forms,for-loop,google-apps-script,Javascript,Forms,For Loop,Google Apps Script,为雇主从事一个相当直接的项目。我需要一个调查表,提交后将转储到电子表格的答案。我正在一个独立的应用程序上使用谷歌应用程序脚本。项目管理层决定反对谷歌表单 我遇到的问题是检索单选按钮值。这里有许多单选按钮问题,我需要能够迭代它们以获得它们的值 用户界面通过GAS的UiApp服务完成: function doGet(e){ var app = UiApp.createApplication(); // set up the form var form = app.createFormP

为雇主从事一个相当直接的项目。我需要一个调查表,提交后将转储到电子表格的答案。我正在一个独立的应用程序上使用谷歌应用程序脚本。项目管理层决定反对谷歌表单

我遇到的问题是检索单选按钮值。这里有许多单选按钮问题,我需要能够迭代它们以获得它们的值

用户界面通过GAS的UiApp服务完成:

function doGet(e){
  var app = UiApp.createApplication();

  // set up the form
  var form = app.createFormPanel();
  var flow = app.createFlowPanel();
  form.add(flow);
  app.add(form);

  // create the radio button groups (they are all Likert scales). 
  // I've written a function that creates a single group (see below)
  for (var i=0; i<24; i++){
    likertScale(i, flow);
  };

  flow.add(app.createSubmitButton('Submit')

  return app;
}
似乎只要我不尝试任何循环,并且我手工编写整个过程,一切都很好


对此有何见解?

您不能以这种方式引用变量“radio”,它将被解释为名为“radio”的属性,请尝试:

请参见此处有关访问对象属性的方法的详细信息:

任何试图复制此功能的人都需要编写一个UI,猜测其中的内容。您可以通过提供重现问题所需的所有(最少)代码来帮助解决问题。
function likertScale(name, flow) {
  // the 'name' argument allows me to pass in the var i from the 
  // for loop above to give each radio button group a unique name
  // the 'flow' argument allows me to pass in the var flow that  
  // I created when setting up the form

  var app = UiApp.getActiveApplication();
  // create the N/A option, assign the group's name, give the button a label 
  // and a value
  flow.add(app.createRadioButton('item'+name, 'N/A').setFormValue('NA'));
  for (var j=1; j<6; j++) {
    // create the 5-point Likert scale; assign the group's name to each button,
    // use j to give each a label and a value
    flow.add(app.createRadioButton('item'+name,j).setFormValue(j);
  }

  return app;
}
function doPost(e) {
  var app = UiApp.getActiveApplication();
  for (var i=0; i<24; i++){
    var radio = 'item'+i; 
      // I've previously set the name of each radio button group 
      // as 'item#', where # is a number 0-23. 
    app.add(app.createLabel().setText('You selected ' + e.parameter.radio));
      // The idea is that each iteration recreates the name of a radio
      // button, then uses that name to inform e.parameter.radio 
  };

  return app;
}
function doPost(e) {
  var app = UiApp.getActiveApplication();
  app.add(app.createLabel().setText('You selected ' + e.parameter.item0

  return app;
}
app.add(app.createLabel().setText('You selected ' + e.parameter[radio]));