简体   繁体   English

Google Apps 脚本:TypeError:未定义不是 function

[英]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")的错误,下面两种模式怎么样?

Pattern 1:模式一:

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.可以使用没有错误。

Pattern 2:模式二:

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.另外,请按如下方式修改脚本。

From: 从:
 var headings = rows[0].map(String.toLowerCase);
To: 至:
 var headings = rows[0].map(Function.prototype.call, String.prototype.toLowerCase);

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: is not a function in Google Apps Script(MailApp 代码) - TypeError : is not a function in Google Apps Script (MailApp code) 类型错误:范围不是 Google Apps 脚本中的 function - TypeError: Range is not a function In Google Apps Script Google Apps脚本函数返回html中未定义的 - Google apps script function returns undefined in html TypeError:无法读取未定义 onEdit 的属性“源” - Google Apps 脚本 - TypeError: Cannot read property 'source' of undefined onEdit - Google Apps Script Google Apps脚本-TypeError:无法从未定义中读取属性“ 0” - Google Apps Script - TypeError: Cannot read property “0” from undefined google apps脚本TypeError:无法调用未定义的方法“ substring” - google apps script TypeError: Cannot call method “substring” of undefined Function 将 undefined 传递给 Google Apps 脚本中调用的 function - Function passes undefined to called function in Google Apps Script Google Apps脚本-UiApp ServerHandler回调函数-值未定义 - Google Apps Script - UiApp ServerHandler Callback function - values are undefined Google Apps 脚本 - 返回未定义 - Google Apps Script - Returning Undefined 为什么我收到 TypeError:在 Google 表格上运行应用程序脚本时无法读取未定义的属性“1”? - Why I'm getting TypeError: Cannot read property '1' of undefined while running an apps script on Google Sheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM