【发布时间】:2015-07-28 09:35:07
【问题描述】:
我在表格中有一个 Google 脚本,它创建了一个侧边栏。侧边栏是使用 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的处理程序,但它总是提出“未定义”。我不相信它会通过任何东西。
【问题讨论】:
标签: javascript scripting google-sheets parameter-passing