嗨,美丽的人们
我在谷歌应用程序脚本中遇到问题,试图生成一个包含多个页面的谷歌表单,其中一个是多项选择题。
我根据问题的答案成功设置了到不同部分的路由。 我面临的问题是最后一个问题:我需要在完成一个部分后将用户重定向到多项选择题部分。
现在,假设我回答了第一个答案,我将被重定向到第一个子部分,但随后我也必须浏览第二个和第三个子部分,尽管它们链接到其他答案。
我想在每个小节的末尾设置一个转到下一页的页面,以跳过其他部分,但不知道如何操作。
这是我当前脚本的简化版本:
// Setting up the multipleChoiceItem:
let mci = form.addMultipleChoiceItem()
.setTitle("Question")
.setRequired(true)
// Setting up the sub-sections
var sectionOne = form.addPageBreakItem()
.setTitle("First Section")
.setHelpText("This is the first section");
form.addTextItem().setTitle("Question inside section one").setRequired(true);
var sectionTwo = form.addPageBreakItem()
.setTitle("Second section")
.setHelpText("This is the second section");
form.addTextItem().setTitle("Questio inside section two").setRequired(true);
var sectionThree = form.addPageBreakItem()
.setTitle("Third section")
.setHelpText("This is the third section");
form.addTextItem().setTitle("Question inside section three").setRequired(true);
// linking the sections to the answers
mci.setChoices([
mci.createChoice("first answer", sectionOne),
mci.createChoice("second answer", sectionTwo),
mci.createChoice("third answer", sectionThree)
]);
// The next page and the rest of the form
var nextPage = form.addPageBreakItem()
.setTitle("The next page")
.setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci");
我很确定它与 pageBreakItems 和 GO_TO_PAGE 有关,可能如下所示:
sectionOne.setGoToPage(FormApp.PageNavigationType.GO_TO_PAGE(nextPage));
但我无法让它工作,似乎 GO_TO_PAGE 方法从未真正实现过,文档中几乎没有关于它的信息。
无论如何,我希望有人已经弄清楚了,我将不胜感激!
非常感谢伙伴们!
感谢 Copilot,我弄清楚了,事实证明我已经非常接近了,但由于缺乏关于这个主题的文档,让它工作非常困难。
这就是它的样子:
// Setting up the multipleChoiceItem:
let mci = form.addMultipleChoiceItem()
.setTitle("Question")
.setRequired(true)
// Setting up the sub-sections
var sectionOne = form.addPageBreakItem()
.setTitle("First Section")
.setHelpText("This is the first section");
form.addTextItem().setTitle("Question inside section one").setRequired(true);
var sectionTwo = form.addPageBreakItem()
.setTitle("Second section")
.setHelpText("This is the second section");
form.addTextItem().setTitle("Questio inside section two").setRequired(true);
var sectionThree = form.addPageBreakItem()
.setTitle("Third section")
.setHelpText("This is the third section");
form.addTextItem().setTitle("Question inside section three").setRequired(true);
// linking the sections to the answers
mci.setChoices([
mci.createChoice("first answer", sectionOne),
mci.createChoice("second answer", sectionTwo),
mci.createChoice("third answer", sectionThree)
]);
// The next page and the rest of the form
var nextPage = form.addPageBreakItem()
.setTitle("The next page")
.setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci");
// [rest of the form]
// Routing to the next page after each answer section
sectionOne.setGoToPage(nextPage);
sectionTwo.setGoToPage(nextPage);
sectionThree.setGoToPage(nextPage);