刚刚开始在 Google Apps 脚本中使用表单服务。需要根据给出的答案引导表单将用户带到特定页面。这是我当前的代码
form.addMultipleChoiceItem()
.setTitle('What would you like to do?')
.setRequired(true)
.setChoiceValues(['Request a new reservation.','Change the date or number of tickets for an existing reservation.'])
现在,我在文档中找到了此部分:枚举页面导航类型 https://developers.google.com/apps-script/reference/forms/page-navigation-type
但他们没有举例说明 Go_To_Page 的使用。 ChoiceValues 的创建对我来说也很奇怪。
有人解决过这个问题吗?
您想要使用 .setChoices([arrayOfChoices]) 而不是 .setChoiceValues,并使用 .createChoice(value, page) 创建选择。
编辑:更新代码以修复错误
function createAMCQuestion(){
var af = FormApp.getActiveForm();
var pRed = af.getItemById("1300443051").asPageBreakItem(); //use findPageIds to get the page id of a pre-created page
var pGreen = af.getItemById("902629766").asPageBreakItem();
var item = af.addMultipleChoiceItem().setTitle('Pic a color?'); // creates the Multiple Choice Question
af.moveItem(item.getIndex(), 1); // Makes the question show up as the second question in the form (starts at 0)
//create choices as an array
var choices = [];
choices.push(item.createChoice('Red', pRed));
choices.push(item.createChoice('Green', pGreen));
// assignes the choices for the question
item.setChoices(choices);
}
function findPageIds(){
var af = FormApp.getActiveForm();
var pages = af.getItems(FormApp.ItemType.PAGE_BREAK);
for (i in pages){
var pName = pages[i].getTitle();
var pId = pages[i].getId();
Logger.log(pName+":"+pId);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)