刚开始在Google Apps脚本中使用Forms Service。需要指示表单将用户带到特定页面,具体取决于给出的答案。这是我目前的代码
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.'])
现在,我在文档中找到了这一部分:Enum PageNavicationType
但是他们没有使用Go_To_Page。另外,ChoiceValues的创建对我来说很不可思议。
有人在那里解决了这个问题吗?
答案 0 :(得分:0)
而不是.setChoiceValues你想使用.setChoices([arrayOfChoices]),并使用.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);
}
}