[英]Google Apps Script: TypeError: undefined is not a function
I'm trying to get this demo Google Sheets Blog Demo to run.我正在尝试运行此演示Google 表格博客演示。 I followed all steps but got this error after running
https://script.google.com/macros/s/[spreadsheetID]/exec?key=abcdef
:我按照所有步骤操作,但在运行
https://script.google.com/macros/s/[spreadsheetID]/exec?key=abcdef
后出现此错误:
TypeError: undefined is not a function (line 19, file "Code")
TypeError: undefined is not a function(第 19 行,文件“代码”)
Line 19 = var headings = rows[0].map(String.toLowerCase);
第 19 行 =
var headings = rows[0].map(String.toLowerCase);
Below is the related function and here the full code .下面是相关的 function 和完整代码。
function doGet(e) {
if (!isAuthorized(e)) {
return buildErrorResponse('not authorized');
}
var options = {
page: getPageParam(e),
category: getCategoryParam(e)
}
var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
var worksheet = spreadsheet.getSheets()[0];
var rows = worksheet.getDataRange().sort({column: 2, ascending: false}).getValues();
var headings = rows[0].map(String.toLowerCase);
var posts = rows.slice(1);
var postsWithHeadings = addHeadings(posts, headings);
var postsPublic = removeDrafts(postsWithHeadings);
var postsFiltered = filter(postsPublic, options.category);
var paginated = paginate(postsFiltered, options.page);
return buildSuccessResponse(paginated.posts, paginated.pages);
}
How to fix this issue?如何解决这个问题?
When I saw the full script at the GitHub, it was found that that script had published 2 years ago.当我在 GitHub 看到完整的脚本时,发现该脚本已于 2 年前发布。 In this case, V8 had not been added.
在这种情况下,没有添加 V8。 In order to avoid the error of
TypeError: undefined is not a function (line 19, file "Code")
, how about the following 2 patterns?为了避免出现
TypeError: undefined is not a function (line 19, file "Code")
的错误,下面两种模式怎么样?
In this pattern, the script is used without V8 runtime.在此模式中,脚本在没有 V8 运行时的情况下使用。 In this case, please disable V8 runtime at the script editor.
在这种情况下,请在脚本编辑器中禁用 V8 运行时。 By this,
var headings = rows[0].map(String.toLowerCase);
这样,
var headings = rows[0].map(String.toLowerCase);
can be used without the error.可以使用没有错误。
In this pattern, the script is used with V8 runtime.在此模式中,脚本与 V8 运行时一起使用。 In this case, please enable V8 runtime at the script editor.
在这种情况下,请在脚本编辑器中启用 V8 运行时。 And also, please modify the script as follows.
另外,请按如下方式修改脚本。
var headings = rows[0].map(String.toLowerCase);
To:
var headings = rows[0].map(Function.prototype.call, String.prototype.toLowerCase);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.