Class Choice

Choice

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

// Create a new form and add a multiple-choice item.
const form = FormApp.create('Form Name');
const 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.
const choices = item.getChoices();
for (let 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