首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Google脚本在Google表单中添加选择

如何使用Google脚本在Google表单中添加选择
EN

Stack Overflow用户
提问于 2021-01-26 09:07:57
回答 1查看 771关注 0票数 0

我试图掌握如何以编程的方式创建Google表单,但不能将选择分配给多个选择项。我可以创建项目(testQuestion)并给它一个标题,但是我的createChoice()语句没有添加选择。

这是我的代码,基于https://developers.google.com/apps-script/reference/forms/page-navigation-type

代码语言:javascript
复制
function testCreateChoices() {

/* modification of
  testPageNavigation()
  to see how to import choices from a range on sheet
*/

// Create a form 
var form = FormApp.create('createChoice Test');

// add a multiple-choice item
var testQuestion = form.addMultipleChoiceItem();
testQuestion.setTitle('Anything here?');
var whatsis = testQuestion.createChoice('bozzle');
var firstChoice = testQuestion.createChoice('this');
testQuestion.createChoice("that");
testQuestion.createChoice("the other");
testQuestion.createChoice("Ouch!");


//add a new multiple-choice item and a pagebreak item
var item = form.addMultipleChoiceItem();
var pageBreak = form.addPageBreakItem();

// Set some choices with go-to-page logic.
var rightChoice = item.createChoice('Vanilla', FormApp.PageNavigationType.SUBMIT);
var wrongChoice = item.createChoice('Chocolate', FormApp.PageNavigationType.RESTART);

// For GO_TO_PAGE, just pass in the page break item. For CONTINUE (normally the default), pass in
// CONTINUE explicitly because page navigation cannot be mixed with non-navigation choices.
var iffyChoice = item.createChoice('Peanut', pageBreak);
var otherChoice = item.createChoice('Strawberry', FormApp.PageNavigatio[enter image description here][1]nType.CONTINUE);
item.setChoices([rightChoice, wrongChoice, iffyChoice, otherChoice]);
  
}

这是我得到的,选择“口吻”等没有显示,以及我想要什么,但不能创造的形象。

非常感谢您的帮助!

这是一个截图,没有标签/选择在“这里有什么东西吗?”

和一个模型与“口吻”,“这个”等作为选择。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-27 11:01:16

没有看到testQuestion 的选项是因为您没有为问题设置选择。

因此,我建议您在创建第一个问题时更新以下内容:

代码语言:javascript
复制
var testQuestion = form.addMultipleChoiceItem();
testQuestion.setChoices([testQuestion.createChoice('bozzle'), testQuestion.createChoice('this'), testQuestion.createChoice("that"), testQuestion.createChoice("the other"), testQuestion.createChoice("Ouch!")]);

createChoice方法仅用于创建选择项,为了将它们实际添加到问题中,还必须使用setChoices方法。

参考文献

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65898506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档