为雇主开展一个相当直接的项目。我需要一份调查表格,在提交时会将答案转储到电子表格中。我正在使用独立应用上的Google Apps脚本。项目管理决定反对谷歌表格。无法遍历Google Apps脚本中的单选按钮值
我遇到问题是检索单选按钮值。有许多单选按钮问题,我需要能够遍历它们以获取它们的值。
用户界面是通过气的了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;
}
我李克特量表()函数:
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;
}
什么是真正困惑对我来说是同时上面的代码中吐出“您选择了不确定的” 24倍,下面的代码完全工作:
function doPost(e) {
var app = UiApp.getActiveApplication();
app.add(app.createLabel().setText('You selected ' + e.parameter.item0
return app;
}
看来,只要我不尝试任何循环,而且我手工编码整个事情,一切都很好。
对此有何见解?
任何人试图重现这将需要编写一个用户界面,猜测你有什么。您可以通过提供重现问题所需的所有(最小)代码来帮助解决问题。 – Mogsdad 2014-12-04 20:19:33
这没问题。 – ishmael624 2014-12-04 20:24:59