Class Choice

选择

与支持选择(如 CheckboxItemListItemMultipleChoiceItem)的 Item 类型相关联的单个选项。

// Create a new form and add a multiple-choice item.
var form = FormApp.create('Form Name');
var item = form.addMultipleChoiceItem();
item.setTitle('Do you prefer cats or dogs?')
    .setChoices([
        item.createChoice('Cats', FormApp.PageNavigationType.CONTINUE),
        item.createChoice('Dogs', FormApp.PageNavigationType.RESTART)
    ]);

// Add another page because navigation has no effect on the last page.
form.addPageBreakItem().setTitle('You chose well!');

// Log the navigation types that each choice results in.
var choices = item.getChoices();
for (var i = 0; i < choices.length; i++) {
Logger.log('If the respondent chooses "%s", the form will %s.',
           choices[i].getValue(),
           choices[i].getPageNavigationType());
}

方法

方法返回类型简介
getGotoPage()PageBreakItem如果响应者选择此选项并完成当前页面,则获取设置为 GO_TO_PAGE 目的地的 PageBreakItem
getPageNavigationType()PageNavigationType获取响应者选择此选项并完成当前页面时发生的 PageNavigationType
getValue()String获取选项的值,受访者查看表单时看到的是标签。
isCorrectAnswer()Boolean获取所选选项是否为问题的正确答案。

详细文档

getGotoPage()

如果响应者选择此选项并完成当前页面,则获取设置为 GO_TO_PAGE 目的地的 PageBreakItem。此方法仅适用于与 MultipleChoiceItems 关联的选项;对于其他选项,该方法会返回 null

弃踢回攻

PageBreakItem - 此选项的 GO_TO_PAGE 目的地,如果没有,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getPageNavigationType()

获取响应者选择此选项并完成当前页面时发生的 PageNavigationType。此方法仅适用于与 MultipleChoiceItems 关联的选项;对于其他选项,该方法会返回 null

弃踢回攻

PageNavigationType - 此选项的导航操作,如果没有,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getValue()

获取选项的值,受访者查看表单时看到的是标签。

弃踢回攻

String - 选项的值

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

isCorrectAnswer()

获取所选选项是否为问题的正确答案。此方法仅适用于测验中的问题;对于非测验表单,它会返回 false。

弃踢回攻

Boolean - 选项是否正确。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms