问题
I created an add-on to import questions & choices as multiple choice items in Forms.
The questions, answers & correct answer were imported perfectly and shows as expected in editing view, however when previewing the form/quiz, some questions have choices missing.
Any ideas?
function createMCQ(k) {
var form = FormApp.getActiveForm();
form.setIsQuiz(true)
.setShuffleQuestions(true)
.setAllowResponseEdits(false)
.setLimitOneResponsePerUser(false)
.setCollectEmail(true)
.setShowLinkToRespondAgain(false);
for (var i = 0, len = k.length; i < len; i++) {
var item = form.addMultipleChoiceItem();
item.setTitle(k[i].question)
.setPoints('1')
.setRequired(true)
.setChoices([
item.createChoice(String(k[i].a), Boolean(k[i].answer =='A')),
item.createChoice(String(k[i].b), Boolean(k[i].answer =='B')),
item.createChoice(String(k[i].c), Boolean(k[i].answer =='C')),
item.createChoice(String(k[i].d), Boolean(k[i].answer =='D')),
]);
}
}
Where it's imported from object like so;
"questions": [
{
"course": "GCSE AQA Biology",
"question": "State the equation that links magnification, image size and actual size.",
"a": "Actual Size = Image Size / Magnification",
"b": "Actual Size = Magnification / Image Size",
"c": "Actual Size = Resolution / Magnification",
"d": "Resolution = Image Size / Magnification",
"topic": "Cells",
"answer": "A",
"id": 2
},
{
"course": "GCSE AQA Biology",
"question": "Which type of microscope has higher magnification and resolving power?",
"a": "Light Microscopes",
"b": "Magnifying Glass",
"c": "Super Microscope",
"d": "Electron microscopes",
"topic": "Cells",
"answer": "D",
"id": 3
}
]
Items imported perfectly as shown when editing:
However, when previewing form, the choices for some of them missing:
This is very random i.e. not isolated to certain questions.
Any suggestion would be appreciated!
回答1:
I think I managed to fix (?) this;
When adding the multiple choice item, I added the choices first before any other properties:
k.map(e => {
var item = form.addMultipleChoiceItem();
item.setTitle(e.question)
.setChoices([
item.createChoice(String(e.a), Boolean(e.answer =='A')),
item.createChoice(String(e.b), Boolean(e.answer =='B')),
item.createChoice(String(e.c), Boolean(e.answer =='C')),
item.createChoice(String(e.d), Boolean(e.answer =='D')),
])
.setPoints('1')
.setRequired(true);
})
Using map instead of for doesn't have to do with anything tho.
I did a few tests, and it looks like the answer choices no longer disappear. Fingers crossed! Might be a Google's bug?
来源:https://stackoverflow.com/questions/65656292/google-form-appscript-item-choices-disappear-when-viewing-however-its-showin