谷歌表单脚本-从单选按钮获取值,目前未定义

Google Sheets script - get value from radio button, currently undefined

本文关键字:目前 未定义 获取 单选按钮 表单 脚本 谷歌      更新时间:2023-09-26

我有一个谷歌脚本在表中创建一个侧边栏。侧边栏是使用UiApp动态生成的,而不是HTML。用户单击其中一个单选按钮来进行选择(其中可能有超过200个,并且它们的值会定期更改,因为它们取自特定的工作表)。

我试图传递单选按钮的值,但它总是出现为未定义:

//get the values over
var MaxRow=250;
var LookIn=0;
var L1; var L2; var L3;
for(LookIn=1;LookIn<MaxRow;LookIn++)
{
  L1=sheet.getRange("AB" + LookIn);
  L2=sheet.getRange("AC" + LookIn);
  L3=sheet.getRange("AD" + LookIn);
  if(L1.getValues()!=""){UIInstance.add(UIInstance.createLabel("_")); UIInstance.add(UIInstance.createHTML("<b>" + L1.getValues() + "</b>"));}
  if(L2.getValues()!=""){UIInstance.add(UIInstance.createHTML("<b> > > " + L2.getValues() + "</b>"));}
  if(L3.getValues()!="")
  {
    var RadioHandler=UIInstance.createServerChangeHandler('radioButtonsChange');
    UIInstance.add(UIInstance.createRadioButton("MyButton").setId(L3.getValues).setText(L3.getValues()).addClickHandler(RadioHandler));
    UIInstance.add(UIInstance.createLabel(""));
  }
}
//add the sidebar
SpreadsheetApp.getUi()
    .showSidebar(UIInstance);
}
function radioButtonsChange(e)
{
  SpreadsheetApp.getUi().alert(e.parameter.source);
}

由于我们有这么多单选按钮,我基本上使用L3.getValues()来设置它们的属性,然后使用处理程序来调用它。目前,它确实会调用处理程序,该处理程序会传递给radioButtonsChange,但它总是显示"undefined"。

好了,我不太清楚我做了什么不同的事情,但是现在它可以工作了。

第一个东西:

var RadioHandler=UIInstance.createServerChangeHandler('radioButtonsChange');
  UIInstance.add(UIInstance.createRadioButton("MyButton").setId(L3.getValues()).setText(L3.getValues()).addClickHandler(RadioHandler));
  UIInstance.add(UIInstance.createLabel(""));

和最后一位:

function radioButtonsChange(e)
{
  SpreadsheetApp.getUi().alert(e.parameter.source);
}

不知道,想想看