简体   繁体   English

Google表格脚本-通过单选按钮获取价值,当前未定义

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

I've got a Google script in Sheets which creates a sidebar. 我在Sheets中有一个Google脚本,可以创建侧边栏。 The sidebar is generated dynamically using the UiApp, rather than HTML. 边栏是使用UiApp而不是HTML动态生成的。 Users click on one of the radio buttons to make their selection (of which there can be over 200, and their values changing regularly, as they're taken from a particular sheet). 用户单击一个单选按钮进行选择(可能有200多个,并且它们的值会定期更改,因为它们取自特定的工作表)。

I'm trying to pass the value of the radio button through, but it's always coming up as undefined: 我正在尝试传递单选按钮的值,但是总是以未定义的形式出现:

//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);
}

As we've got so many radio buttons, I'm basically using L3.getValues() to set their properties, then the handler to hopefully call it up. 由于有很多单选按钮,因此我基本上是使用L3.getValues()来设置其属性,然后使用处理程序来调用它。 Currently it does call the handler which goes through to the radioButtonsChange, but it's always bringing up "undefined". 当前,它确实调用了传递到radioButtonsChange的处理程序,但是它始终显示“未定义”。 I'm not convinced it's passing anything through. 我不确信它正在传递任何东西。

Okay, don't quite know what I did differently but it's working now. 好的,不太了解我做了什么,但是现在可以了。

First stuff: 第一件事:

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

And the last bit: 最后一点:

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

Not a clue, go figure. 没头绪,图吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM