如何在不使用应用程序的情况下在doGet函数上测试对象的值 [英] How to test value of objects on a doGet function without using application

查看:48
本文介绍了如何在不使用应用程序的情况下在doGet函数上测试对象的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的英语不好,而且我的水平很低.我仍然找不到任何东西.也许你可以帮我吗?

Due to my bad english, and my low-level. I still find nothing about it. Maybe you could help me ?

我曾经使用Logger.log()测试我想要的东西的内容.我不是经验丰富的开发人员,所以我很难轻松地调试我的代码,尤其是在Google Apps Script上,因此也许有一些技巧可以绕过我的问题.

I used to use Logger.log() to test content of things I want. I'm not an experienced developer, so I don't easily get in hand way to debug my code, especially on Google Apps Script, so maybe there is tricks to bypass my issue.

问题很简单:

function doGet(e) {
  var currentUser = Session.getActiveUser().getEmail();
  var ssUrl =  e.parameter.url;
  var sheetName = e.parameter.sheet;
  var a1Notation = e.parameter.range;

如您所见,我使用Spreadsheet修改传递的参数(好吧,您看不到它是电子表格,但您不在乎). 但是,如果运行脚本,它显然将其视为未定义,并且我无法在10行之后尝试对象的值.我只是想知道是否有一种方法,例如断点,以便不必在每次调试时都复制URL String,sheet等.

As you can see, i use parameter passed by a Spreadsheet modification(well you can't see that it is a spreadsheet but you shouldn't care). But If run the script, It obviously see it as undefined and i can't try value of an object 10 lines after. I just would like to know if there is a way, such as a breakpoint, in order not to have to copy the URL String , sheet etc.. each time I need to debug.

推荐答案

脚本编辑器提供了调试器和断点,以防万一您没有注意到.

The Script Editor offers a debugger and breakpoints, in case you haven't noticed.

为了调试doGet函数,创建另一个模仿GET调用的函数很方便.首先,我将创建一个日志记录网络应用程序:

In order to debug the doGet function, it's convenient to create another function that imitates a GET call. To begin with, I would create a logging web app:

function doGet(e) {
  return ContentService.createTextOutput(JSON.stringify(e));
}

然后获取您的GET请求来源,而不是真正的请求调用日志记录Web应用程序.记录返回的JSON字符串,并将其用于此函数中.

Then get your source of GET requests call the logging web app instead of the real one. Record the JSON string returned and use it in a function such as this one.

function fakeGet() {
  var eventObject = 
    {
      "parameter": {
        "action": "view",
        "page": "3"
      },
      "contextPath": "",
      "contentLength": -1,
      "queryString": "action=view&page=3",
      "parameters": {
        "action": ["view"],
        "page": ["3"]
      }
    }
  doGet(eventObject);
}

此处fakeGet模仿查询字符串?action=view&page=3的GET请求调用.您可以从脚本编辑器启动fakeGet并使用调试器观察doGet函数的工作方式.

Here fakeGet imitates a GET request call with query string ?action=view&page=3. You can launch fakeGet from script editor and use the debugger to observe how doGet function works.

这篇关于如何在不使用应用程序的情况下在doGet函数上测试对象的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆