getType(). getvalue()不工作(Google表单)



我试图从一个Google Form项目中获得项目类型的字符串,但它不会工作。

// Get the item type.
function test1() {
// Get the form.
const testForm8 = FormApp.openById('spreadsheetId');
// Get the item array.
const itemArray = testForm8.getItems();
// Get the first item.
const item = itemArray[0];
// Get the item type.
const itemType = item.getType();
// Get the item type as a string.
// !!!getValue is not working!!!
const itemTypeString = itemType.getValue();
console.log(itemTypeString);
}

根据你的问题,我得到你不能访问Item.getType()结果。如果我理解正确的话,那么您只需要对代码进行微小的更改就可以继续。正如链接文档中解释的那样,getType()返回一个ItemType枚举。如果您想记录它的值,可以直接使用类似于下面的代码:

function test1() {
const testForm8 = FormApp.openById(
'12Fnwvg5ILGJSOPkQaDSdVikKWlBrheiHHQqxM8rLTW4');
const itemArray = testForm8.getItems();
const item = itemArray[0];
const itemType = item.getType();
console.log(itemType);
}

如果你对这种方法有疑问,请问我。

这个成功了

// Get the item type.
function test1() {
// Get the form.
const testForm8 = FormApp.openById('12Fnwvg5ILGJSOPkQaDSdVikKWlBrheiHHQqxM8rLTW4');
// Get the item array.
const itemArray = testForm8.getItems();
// Get the first item.
const item = itemArray[0];
// Get the item type.
const itemType = item.getType();
// Get the item type as a string.
// !!!getValue is not working!!!
const itemTypeString = itemType.toString();
console.log(itemTypeString);
}

最新更新