getID()无法识别

时间:2013-02-28 08:02:16

标签: javascript google-apps-script google-drive-api

我正在编写一个脚本,让Google表格跟踪作者小说在Google云端硬盘中的写作进度。

我正在尝试计算给定文档的字数,并将其推送到下面代码中的数组中:

// Gets each chapter's word count and pushes it into the numberTitleCount array.

for(c in files){
  var counter = 0;
  var ID = files[c].getID();
  var doc = DocsList.getFileById(ID);

  var text = doc.getText();
  var textArray = text.split(" ");
  counter = textArray.length;
  numberTitleCount[c].push(counter);
}

问题是,当我运行脚本时,会发生错误。这是错误:

TypeError:无法在对象文件中找到函数getID。 (第20行,文件“commentCount”)

我不确定错误是什么。 files是一个文件数组,所以调用文件[c] .getID()应该得到指定文件的ID,但没有这样的运气。我知道阵列很好,因为我尝试添加单词计数功能之前,我使用相同的数组成功获得章节编号和标题。

非常感谢您对此问题的任何意见!

〜诺勒

1 个答案:

答案 0 :(得分:1)

如果您使用脚本编辑器的自动完成功能,则可以更轻松地捕获此问题。 (Ctrl + Space)。

问题是该函数名为getId(),而不是getID()Documentation