Class MultipleChoiceItem

MultipleChoiceItem

問題項目,可讓作答者從圓形按鈕清單或選用的「其他」欄位選取一個選項。您可以透過 Form 存取或建立項目。用於測驗時,系統會自動為這些項目評分。

// Open a form by ID and add a new multiple choice item.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var item = form.addMultipleChoiceItem();
item.setTitle('Do you prefer cats or dogs?')
    .setChoices([
        item.createChoice('Cats'),
        item.createChoice('Dogs')
     ])
    .showOtherOption(true);

方法

方法傳回類型簡短說明
createChoice(value)Choice建立新的選項。
createChoice(value, isCorrect)Choice建立新的選項。
createChoice(value, navigationItem)Choice建立新選項,提供頁面導覽選項,讓您跳到指定分頁項目。
createChoice(value, navigationType)Choice建立含有網頁導覽選項的新選項。
createResponse(response)ItemResponse為這個選擇題項目建立新的 ItemResponse
duplicate()MultipleChoiceItem建立這個項目的副本,並附加到表單末尾。
getChoices()Choice[]取得物品的所有選項。
getFeedbackForCorrect()QuizFeedback傳回作答者正確回答問題後會看到的意見回饋。
getFeedbackForIncorrect()QuizFeedback傳回作答者錯誤回答時看到的意見回饋。
getHelpText()String取得項目的說明文字 (有時稱為 ImageItemsPageBreakItemsSectionHeaderItems 等版面配置項目的說明文字)。
getId()Integer取得項目的專屬 ID。
getIndex()Integer取得表單中所有項目的索引。
getPoints()Integer傳回可評分項目的分數值。
getTitle()String取得項目的標題 (在 SectionHeaderItem 中則稱為標題文字)。
getType()ItemType取得項目的類型,以 ItemType 表示。
hasOtherOption()Boolean決定項目是否提供「其他」選項。
isRequired()Boolean決定作答者是否必須回答問題。
setChoiceValues(values)MultipleChoiceItem從字串陣列設定項目的選項。
setChoices(choices)MultipleChoiceItem設定項目的選項陣列。
setFeedbackForCorrect(feedback)MultipleChoiceItem設定在作答者正確回答問題時,向他們顯示意見回饋。
setFeedbackForIncorrect(feedback)MultipleChoiceItem設定在作答者答錯時向他們顯示意見回饋。
setHelpText(text)MultipleChoiceItem設定項目的說明文字 (有時稱為 ImageItemsPageBreakItemsSectionHeaderItems 等版面配置項目的說明文字)。
setPoints(points)MultipleChoiceItem設定可評分項目的價值分數。
setRequired(enabled)MultipleChoiceItem設定作答者是否必須回答問題。
setTitle(title)MultipleChoiceItem設定項目的標題 (在 SectionHeaderItem 中也稱為標題文字)。
showOtherOption(enabled)MultipleChoiceItem設定項目是否提供「其他」選項。

內容詳盡的說明文件

createChoice(value)

建立新的選項。

參數

名稱類型說明
valueString作答者檢視表單時看到的標籤值

回攻員

Choice:新選項

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

createChoice(value, isCorrect)

建立新的選項。

參數

名稱類型說明
valueString作答者檢視表單時看到的標籤值
isCorrectBoolean選項是否為正確答案

回攻員

Choice:新選項

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

createChoice(value, navigationItem)

建立新選項,提供頁面導覽選項,讓您跳到指定分頁項目。這相當於 navigationType 設定為 FormApp.PageNavigationType.GO_TO_PAGEcreateChoice(value, navigationType)。使用頁面導覽的選項無法同時與不使用頁面導覽的選項合併。

作答者完成含有選項的頁面後,且只有在作答者選擇該選項時,系統才會瀏覽頁面。如果作答者在同一個頁面上使用頁面瀏覽操作說明選擇多個選項,則只有最後一個導覽選項會生效。瀏覽頁面也不會影響表單的最後一個頁面。

參數

名稱類型說明
valueString作答者檢視表單時看到的標籤值
navigationItemPageBreakItem即可前往

回攻員

Choice:新選項

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

createChoice(value, navigationType)

建立含有網頁導覽選項的新選項。無法合併使用網頁瀏覽的選項,與不使用頁面導覽的選項合併在同一個項目中。

作答者完成含有選項的頁面後,且只有在作答者選擇該選項時,系統才會瀏覽頁面。如果作答者在同一個頁面上使用頁面瀏覽操作說明選擇多個選項,則只有最後一個導覽選項會生效。瀏覽頁面也不會影響表單的最後一個頁面。

參數

名稱類型說明
valueString作答者檢視表單時看到的標籤值
navigationTypePageNavigationType所選導覽類型

回攻員

Choice:新選項

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

createResponse(response)

為這個選擇題項目建立新的 ItemResponse。如果 response 引數與這個項目的有效選項不符,就會擲回例外狀況,除非 showOtherOption(enabled) 設為 true

參數

名稱類型說明
responseString這個選擇題的有效答案

回攻員

ItemResponse:項目回應

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

duplicate()

建立這個項目的副本,並附加到表單末尾。

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem 的重複項目,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getChoices()

取得物品的所有選項。

回攻員

Choice[]:選項陣列

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getFeedbackForCorrect()

傳回作答者正確回答問題後會看到的意見回饋。

回攻員

QuizFeedback:意見回饋 (如果有的話)。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getFeedbackForIncorrect()

傳回作答者錯誤回答時看到的意見回饋。

回攻員

QuizFeedback:意見回饋 (如果有的話)。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getHelpText()

取得項目的說明文字 (有時稱為 ImageItemsPageBreakItemsSectionHeaderItems 等版面配置項目的說明文字)。

回攻員

String:商品的說明文字或說明文字

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getId()

取得項目的專屬 ID。

回攻員

Integer:項目的 ID

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getIndex()

取得表單中所有項目的索引。

回攻員

Integer:項目的索引

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getPoints()

傳回可評分項目的分數值。

回攻員

Integer:問題可獲得的分數。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getTitle()

取得項目的標題 (在 SectionHeaderItem 中則稱為標題文字)。

回攻員

String:項目的標題或標題文字

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

getType()

取得項目的類型,以 ItemType 表示。

回攻員

ItemType:項目的類型

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

hasOtherOption()

決定項目是否提供「其他」選項。

回攻員

Booleantrue如果該項目有「其他」選項,則傳回 false

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

isRequired()

決定作答者是否必須回答問題。

回攻員

Boolean:作答者是否須回答問題

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setChoiceValues(values)

從字串陣列設定項目的選項。如果指定的陣列為空白,就會擲回例外狀況。

// Open a form by ID and add a new list item.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?');
item.setChoiceValues(['Dogs', 'Cats']);

參數

名稱類型說明
valuesString[]選擇值陣列,作答者在檢視表單時會顯示為標籤

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setChoices(choices)

設定項目的選項陣列。如果指定的陣列為空白或包含 null 元素,就會擲回例外狀況。

// Open a form by ID and add a new list item.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?')
item.setChoices([
    item.createChoice('Cats'),
    item.createChoice('Dogs')
]);

參數

名稱類型說明
choicesChoice[]一個選擇陣列

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

擲回

Error:如果指定陣列為 null、空白或包含 null 元素

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setFeedbackForCorrect(feedback)

設定在作答者正確回答問題時,向他們顯示意見回饋。

// Open a form by ID and add a new list item.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var item = form.addListItem();
item.setTitle('Do you prefer cats or dogs?');
// Set "Dogs" as the correct answer to this question.
item.setChoices([
  item.createChoice('Dogs', true),
  item.createChoice('Cats', false)]);
// Add feedback which will be shown for correct responses; ie "Dogs".
item.setFeedbackForCorrect(
    FormApp.createFeedback().setDisplayText("Dogs rule, cats drool.").build());

參數

名稱類型說明
feedbackQuizFeedback新的意見回饋空值會清除意見回饋。

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setFeedbackForIncorrect(feedback)

設定在作答者答錯時向他們顯示意見回饋。

參數

名稱類型說明
feedbackQuizFeedback新的意見回饋

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setHelpText(text)

設定項目的說明文字 (有時稱為 ImageItemsPageBreakItemsSectionHeaderItems 等版面配置項目的說明文字)。

參數

名稱類型說明
textString新的說明文字

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setPoints(points)

設定可評分項目的價值分數。新項目的預設值是 0。

參數

名稱類型說明
pointsInteger問題項目的價值分數

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setRequired(enabled)

設定作答者是否必須回答問題。

參數

名稱類型說明
enabledBoolean作答者是否必須回答

回攻員

MultipleChoiceItem:目前的項目 (用於鏈結)

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

setTitle(title)

設定項目的標題 (在 SectionHeaderItem 中也稱為標題文字)。

參數

名稱類型說明
titleString新的標題或標題文字

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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

showOtherOption(enabled)

設定項目是否提供「其他」選項。新 CheckboxItemMultipleChoiceItem 的預設值為 false

參數

名稱類型說明
enabledBoolean如果項目有「其他」選項,則為 true;否則為 false

回攻員

MultipleChoiceItem — 此 MultipleChoiceItem,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

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