我正在尝试将Google测验项目从一个Form
复制到另一个,这似乎已经完全成功了。但是,我忘记了其中一些项目附有图像。
没有任何记录可以建议如何访问这些内容,但我已尝试getImage
和Item
Item.asMultipleChoiceItem
,但都未被识别。它只是最后两行无效的代码。
我得到了
TypeError:在对象
中找不到函数getImage
Item
或
TypeError:在对象
中找不到函数getImage
MultipleChoiceItem
function copyMultipleChoiceItem(item1, item2) {
// copies MC question item1 to item2 - tested PDW 17/05/20
// copy of feedback now working - tested PDW 17/05/30
//
var item1MC = item1.asMultipleChoiceItem();
// basic question items
item2.setTitle(item1.getTitle());
item2.setHelpText(item1.getHelpText());
item2.setPoints(item1MC.getPoints());
item2.setRequired(item1MC.isRequired());
// the choices
var choices = item1MC.getChoices();
for (var i = 0; i < choices.length; i++) {
item2.createChoice(choices[i].getValue(), choices[i].isCorrectAnswer());
}
item2.setChoices(choices);
// the feedback
var feedback1 = item1MC.getFeedbackForCorrect();
item2.setFeedbackForCorrect(feedback1);
var feedback1 = item1MC.getFeedbackForIncorrect();
item2.setFeedbackForIncorrect(feedback1);
// the image
var image1 = item1.getImage();
item2.setImage(image1);
}
答案 0 :(得分:0)
确保您的item1是ImageItem
,我已根据您的代码制作了测试脚本。这是片段:
function myFunction() {
// Create and open a form.
var newForm = FormApp.create('Form Name');
var img = UrlFetchApp.fetch('https://www.google.com/images/srpr/logo4w.png');
var pageTwo = newForm.addPageBreakItem().setTitle('Page Two');
var newImage = newForm.addImageItem()
.setTitle('Google')
.setHelpText('Google Logo') // The help text is the image description
.setImage(img);
var pageThree = newForm.addPageBreakItem().setTitle('Page Three');
var img2 = newForm.addImageItem();
ImageCopy(newImage,img2);
}
function ImageCopy(itemImage,img2){
var image1 = itemImage.getImage();
img2.setImage(image1);
}
结果如下:
希望这有帮助。
答案 1 :(得分:0)
here is the result of the code
if(questionType=='MULTIPLE_CHOICE'){
var img = UrlFetchApp.fetch(www.myWebSite.com/tomato.png);
form.addImageItem()
.setTitle('Quizz')
.setHelpText('Any number off answer')
.setImage(img);
var item = form.addMultipleChoiceItem();
item.setChoices([
item.createChoice('tomato'),
item.createChoice('pomodoro'),
item.createChoice('tomate'),
item.createChoice('tomata'),
]);
这有点奇怪,但这是我发现使测验显示的唯一方法,就像我在测验中添加图像一样(使用不带脚本的表单编辑器)。 现在您对电子表格的响应有疑问,对不起