Google Sheets脚本 - 从单选按钮获取值,目前未定义 [英] Google Sheets script - get value from radio button, currently undefined

查看:144
本文介绍了Google Sheets脚本 - 从单选按钮获取值,目前未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



  / 

我试图传递单选按钮的值,但它始终显示为undefined: /获得
以上的值var MaxRow = 250;
var LookIn = 0;
var L1; var L2; var L3; (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(< 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());


//添加边栏
SpreadsheetApp.getUi()
.showSidebar(UIInstance);
}

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



$ b $ p
$ b因为我们有很多单选按钮,我基本上使用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);
}

不是线索,请转到图。


I've got a Google script in Sheets which creates a sidebar. The sidebar is generated dynamically using the UiApp, rather than 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).

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. Currently it does call the handler which goes through to the radioButtonsChange, but it's always bringing up "undefined". 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.

这篇关于Google Sheets脚本 - 从单选按钮获取值,目前未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆