問題項目,可讓作答者從下拉式選單中選取一個選項。您可以透過 Form 存取或建立項目。
// Open a form by ID and add a new list item. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?').setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]);
方法
內容詳盡的說明文件
createChoice(value)
createChoice(value, isCorrect)
createChoice(value, navigationItem)
建立新的選項,並提供頁面導覽選項,可跳至指定的換頁符項目。這相當於將 navigationType 設為 FormApp.PageNavigationType.GO_TO_PAGE 的 createChoice(value, navigationType)。使用頁面導覽的選項,無法與未使用頁面導覽的選項合併在同一個項目中。
受訪者完成含有該選項的頁面後,系統才會進行頁面導覽,且僅限受訪者選擇該選項時。如果作答者在同一頁面中選擇多個選項,且這些選項都含有頁面導覽指示,只有最後一個導覽選項會生效。網頁瀏覽也不會影響表單的最後一頁。
請注意,在項目上使用網頁瀏覽會將路徑硬式編碼,因此不應同時使用 showOtherOption(true)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
value | String | 選項的值,作答者查看表單時會看到這個標籤 |
navigation | Page | 要前往的項目 |
回攻員
Choice:新選擇
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
createResponse(response)
為這個清單項目建立新的 ItemResponse。如果 response 引數與這個項目的有效選項不符,就會擲回例外狀況。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
response | String | 這個清單項目的有效答案 |
回攻員
ItemResponse - 項目回應
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
duplicate()
getChoices()
getFeedbackForCorrect()
傳回受訪者正確回答問題時顯示的回饋。
回攻員
QuizFeedback|null:意見回饋 (如有)。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
getFeedbackForIncorrect()
傳回作答者回答問題錯誤時顯示的意見回饋。
回攻員
QuizFeedback|null:意見回饋 (如有)。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
getHelpText()
取得項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItems、PageBreakItems 和 SectionHeaderItems)。
回攻員
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()
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. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); item.setChoiceValues(['Dogs', 'Cats']);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
values | String[] | 選項值陣列,作答者查看表單時會看到這些值做為標籤 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
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. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const item = form.addListItem(); item.setTitle('Do you prefer cats or dogs?'); item.setChoices([item.createChoice('Cats'), item.createChoice('Dogs')]);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
choices | Choice[] | 選項陣列 |
回攻員
擲回
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. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const 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().setText('Dogs rule, cats drool.').build(), );
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
feedback | Quiz | 新意見回饋。空值會清除意見回饋。 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
setFeedbackForIncorrect(feedback)
設定作答者答錯問題時顯示的意見回饋。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
feedback | Quiz | 新的意見回饋 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
setHelpText(text)
設定項目的說明文字 (有時稱為版面配置項目的說明文字,例如 ImageItems、PageBreakItems 和 SectionHeaderItems)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 新的說明文字 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms
setPoints(points)
setRequired(enabled)
setTitle(title)
設定項目的標題 (如果是 SectionHeaderItem,有時稱為標頭文字)。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
title | String | 新標題或標頭文字 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/forms.currentonly -
https://www.googleapis.com/auth/forms