You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Google Script为选择题设置反馈?遇TypeError报错求助

解决Google表单自动化生成中添加反馈的TypeError问题

报错的核心原因是用错了FeedbackBuilder的方法名——你写的setDisplayText并不是Google Apps Script中合法的方法,正确的设置反馈文本的方法是setText。

修正后的代码如下:

const questionItem = form.addMultipleChoiceItem();
questionItem.setTitle(qData.question);

// 创建选项并标记正确答案
const choices = qData.options.map(option =>
    questionItem.createChoice(option.text, option.isCorrect)
);

questionItem.setChoices(choices);

// 替换setDisplayText为setText
const feedback = FormApp.createFeedback().setText(qData.explanation).build();

questionItem.setFeedbackForCorrect(feedback);
questionItem.setFeedbackForIncorrect(feedback);

如果需要给正确、错误回答分别设置不同反馈,可单独创建两个反馈对象:

const correctFeedback = FormApp.createFeedback().setText("回答正确!").build();
const incorrectFeedback = FormApp.createFeedback().setText("回答错误,正确答案参考:xxx").build();

questionItem.setFeedbackForCorrect(correctFeedback);
questionItem.setFeedbackForIncorrect(incorrectFeedback);

内容的提问来源于stack exchange,提问作者Joy Ankit Minz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 09:47:09